本帖最后由 JForcex 于 2012-12-17 22:28:49 编辑

解决方案 »

  1.   

    ————————————————————————————————————————————————
    Struts.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
    <package name="processes" extends="struts-default">
    <action name="deployAction" class="com.action.Deploy">
    <result>index.jsp</result>
    </action>
    </package>
    </struts>
    ————————————————————————————————————————————————
    applicationContext.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- jbpm4.4工作流  -->
    <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
    <property name="jbpmCfg" value="spring-jbpm4.cfg.xml" />
    </bean>
       <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
    <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService"/>
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>

    <!-- 数据源配置 -->
    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
    value="net.sourceforge.jtds.jdbc.Driver">
    </property>
    <property name="url"
    value="jdbc:jtds:sqlserver://localhost:1433/DB">
    </property>
    <property name="username" value="sa"></property>
    <property name="password" value="111111"></property>
    </bean>

    <!-- sessionFactory -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.SQLServerDialect
    </prop>
    </props>
    </property>

    <property name="mappingLocations">
    <list>
    <value>classpath:jbpm.execution.hbm.xml</value>
    <value>classpath:jbpm.history.hbm.xml</value>
    <value>classpath:jbpm.identity.hbm.xml</value>
    <value>classpath:jbpm.repository.hbm.xml</value>
    <value>classpath:jbpm.task.hbm.xml</value>
        </list>
    </property>
    </bean>

    <!-- DAO -->

    <!-- action -->
    <bean id="DeployAction" class="com.action.Deploy">
    <property name="processEngine" ref="processEngine"></property>
    <property name="repositoryService" ref="repositoryService"/>
    <property name="executionService" ref="executionService"/>
    <property name="taskService" ref="taskService"/>
    <property name="historyService" ref="historyService"/>
    <property name="managementService" ref="managementService"/>
    </bean>

    <!-- 事务 -->
    <bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    <property name="nestedTransactionAllowed" value="true" />
    </bean>

    </beans>
    ————————————————————————————————————————————————
    Deploy.java
    package com.action;import org.jbpm.api.ExecutionService;
    import org.jbpm.api.HistoryService;
    import org.jbpm.api.ManagementService;
    import org.jbpm.api.ProcessEngine;
    import org.jbpm.api.RepositoryService;
    import org.jbpm.api.TaskService;import com.opensymphony.xwork2.ActionSupport;public class Deploy extends ActionSupport {
    /** XueJing
     *  test process deploying
     */
    ProcessEngine processEngine;
    RepositoryService repositoryService;
    ExecutionService executionService;
    TaskService taskService;
    HistoryService historyService;
    ManagementService managementService;
    private static final long serialVersionUID = 1L;
    @Override
    public String execute() throws Exception {
    String deploymentid = repositoryService.createDeployment()
        .addResourceFromClasspath("com/services/leave.jpdl.xml")
        .deploy();
    System.out.println("deploy success! deploymentid="+deploymentid);
    return SUCCESS;
    }
    public ProcessEngine getProcessEngine() {
    return processEngine;
    }
    public void setProcessEngine(ProcessEngine processEngine) {
    this.processEngine = processEngine;
    }
    public RepositoryService getRepositoryService() {
    return repositoryService;
    }
    public void setRepositoryService(RepositoryService repositoryService) {
    this.repositoryService = repositoryService;
    }
    public ExecutionService getExecutionService() {
    return executionService;
    }
    public void setExecutionService(ExecutionService executionService) {
    this.executionService = executionService;
    }
    public TaskService getTaskService() {
    return taskService;
    }
    public void setTaskService(TaskService taskService) {
    this.taskService = taskService;
    }
    public HistoryService getHistoryService() {
    return historyService;
    }
    public void setHistoryService(HistoryService historyService) {
    this.historyService = historyService;
    }
    public ManagementService getManagementService() {
    return managementService;
    }
    public void setManagementService(ManagementService managementService) {
    this.managementService = managementService;
    }}
    ————————————————————————————————————————————————
      

  2.   

    index.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        <title>My JSP 'index.jsp' starting page</title>
      </head>
      
      <body>
        This is my JSP page.
        <s:action name="deployAction"/>
      </body>
    </html>
      

  3.   

    环境:
    MyEclipse 8.6
    Tomcat 5.5
    SQLServer 2008 R2