jBPM4实战系列(二)jBPM4.4+ssh 整合配置及完整实例

来源:互联网 发布:域通电话 软件 编辑:程序博客网 时间:2024/05/18 22:55
   整合jBPM4.4+ssh过程(spring 接管struts2和hibernate,例中都整合在application.xml中,没有单独的jbpm.hibernate.cfg.xml):

            

          1.在sessionFactory的mappingLocations属性加入以下几个jbpm.*.hbm.xml由jBPM自带

                <value>classpath:jbpm.repository.hbm.xml</value>  
                <value>classpath:jbpm.execution.hbm.xml</value>  
                <value>classpath:jbpm.history.hbm.xml</value>  
                <value>classpath:jbpm.task.hbm.xml</value>  
                <value>classpath:jbpm.identity.hbm.xml</value>

         

         2.jBPM自己内部的配置(spring来接管processEngine)

               <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />
               <bean id="processEngine" factory-bean="springHelper" factory-

                                method="createProcessEngine"  />

              

               这样子就配好啦。只要在要用的地方注入processEngine就可以了!简单吧

 

         3.当然为了编程的方便,可以自己写个工具类,直接就可以通过注入这个类来获取所需要的jBPM服务

 

              

Java代码  收藏代码
  1. package com.ht.util;  
  2.   
  3. import java.util.List;  
  4. import java.util.Map;  
  5. import java.util.zip.ZipInputStream;  
  6. import org.jbpm.api.ExecutionService;  
  7. import org.jbpm.api.HistoryService;  
  8. import org.jbpm.api.ManagementService;  
  9. import org.jbpm.api.ProcessDefinition;  
  10. import org.jbpm.api.ProcessEngine;  
  11. import org.jbpm.api.ProcessInstance;  
  12. import org.jbpm.api.RepositoryService;  
  13. import org.jbpm.api.TaskService;  
  14. import org.jbpm.api.task.Task;  
  15.   
  16. /** 
  17.  * jBPM4.4工具类 
  18.  *  
  19.  * @author ht 
  20.  *  
  21.  */  
  22. public class JBPMUtil {  
  23.       
  24.     private ProcessEngine processEngine;  
  25.     private RepositoryService repositoryService = null;  
  26.     private ExecutionService executionService = null;  
  27.     private TaskService taskService = null;  
  28.     private HistoryService historyService = null;  
  29.     private ManagementService managementService = null;  
  30.       
  31.     public JBPMUtil(){  
  32.           
  33.     }  
  34.     public JBPMUtil(ProcessEngine processEngine) {  
  35.         this.processEngine = processEngine;  
  36.         repositoryService = processEngine.getRepositoryService();  
  37.         executionService = processEngine.getExecutionService();  
  38.         taskService = processEngine.getTaskService();  
  39.         historyService = processEngine.getHistoryService();  
  40.         managementService = processEngine.getManagementService();  
  41.     }  
  42.   
  43.       
  44.   
  45.     public ProcessEngine getProcessEngine() {  
  46.         return processEngine;  
  47.     }  
  48.   
  49.     public void setProcessEngine(ProcessEngine processEngine) {  
  50.         this.processEngine = processEngine;  
  51.         System.out.println("processEngine="+processEngine);  
  52.         repositoryService = processEngine.getRepositoryService();  
  53.         executionService = processEngine.getExecutionService();  
  54.         taskService = processEngine.getTaskService();  
  55.         historyService = processEngine.getHistoryService();  
  56.         managementService = processEngine.getManagementService();  
  57.     }  
  58.   
  59.     public RepositoryService getRepositoryService() {  
  60.         return repositoryService;  
  61.     }  
  62.   
  63.     public void setRepositoryService(RepositoryService repositoryService) {  
  64.         this.repositoryService = repositoryService;  
  65.     }  
  66.   
  67.     public ExecutionService getExecutionService() {  
  68.         return executionService;  
  69.     }  
  70.   
  71.     public void setExecutionService(ExecutionService executionService) {  
  72.         this.executionService = executionService;  
  73.     }  
  74.   
  75.     public TaskService getTaskService() {  
  76.         return taskService;  
  77.     }  
  78.   
  79.     public void setTaskService(TaskService taskService) {  
  80.         this.taskService = taskService;  
  81.     }  
  82.   
  83.     public HistoryService getHistoryService() {  
  84.         return historyService;  
  85.     }  
  86.   
  87.     public void setHistoryService(HistoryService historyService) {  
  88.         this.historyService = historyService;  
  89.     }  
  90.   
  91.     public ManagementService getManagementService() {  
  92.         return managementService;  
  93.     }  
  94.   
  95.     public void setManagementService(ManagementService managementService) {  
  96.         this.managementService = managementService;  
  97.     }  
  98.       
  99.       
  100.       
  101.     /** 
  102.      * 部署新流程定义 
  103.      * @param resourceName 
  104.      * @return 返回流程定义id 
  105.      */  
  106.     public String deployNew(String resourceName) {  
  107.         return repositoryService.createDeployment().addResourceFromClasspath(  
  108.                 resourceName).deploy();  
  109.     }  
  110.   
  111.       
  112.     /** 
  113.      * 部署新流程定义(zip) 
  114.      * @param resourceName 
  115.      * @return 返回流程定义id 
  116.      */  
  117.     public String deployZipNew(String resourceZipName){  
  118.         ZipInputStream zis = new ZipInputStream(this.getClass().getResourceAsStream(resourceZipName));  
  119.           
  120.         return repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();     
  121.           
  122.     }  
  123.       
  124.       
  125.     /** 
  126.      * 开始一个流程实例 
  127.      * @param id 
  128.      * @param map 
  129.      * @return 
  130.      */  
  131.       
  132.     public ProcessInstance startPIById(String id,Map<String,?> map){    
  133.           
  134.         return executionService.startProcessInstanceById(id, map);        
  135.           
  136.     }  
  137.       
  138.     /** 
  139.      * 完成任务 
  140.      * @param taskId 
  141.      * @param map 
  142.      */  
  143.       
  144.     public void completeTask(String taskId,Map map){  
  145.           
  146.         taskService.completeTask(taskId, map);    
  147.     }  
  148.       
  149.     /** 
  150.      * 完成任务 
  151.      * @param taskId 
  152.      */  
  153.     public void completeTask(String taskId){  
  154.         taskService.completeTask(taskId);  
  155.     }  
  156.       
  157.       
  158.     /** 
  159.      * 将任务流转到指定名字的流程outcome中去 
  160.      * @param taskId 
  161.      * @param outcome 
  162.      */  
  163.     public void completeTask(String taskId,String outcome){  
  164.         taskService.completeTask(taskId, outcome);  
  165.     }  
  166.   
  167.     /** 
  168.      * 获得所有发布了的流程 
  169.      * @return 
  170.      */  
  171.     public List<ProcessDefinition> getAllPdList(){  
  172.         return repositoryService.createProcessDefinitionQuery().list();  
  173.     }  
  174.       
  175.     /** 
  176.      * 获得所有流程实例 
  177.      * @return 
  178.      */  
  179.     public List<ProcessInstance> getAllPiList(){  
  180.         return executionService.createProcessInstanceQuery().list();  
  181.     }  
  182.       
  183.     /** 
  184.      * 根据流程实例Id,即executionId获取指定的变量值 
  185.      * @param executionId 
  186.      * @param variableName 
  187.      * @return 
  188.      */  
  189.     public Object getVariableByexecutionId(String executionId,String variableName){  
  190.         return executionService.getVariable(executionId, variableName);  
  191.     }  
  192.       
  193.       
  194.     /** 
  195.      * 根据任务id,即taskId获取指定变量值 
  196.      * @param taskId 
  197.      * @param variableName 
  198.      * @return 
  199.      */  
  200.     public Object getVariableByTaskId(String taskId,String variableName){  
  201.         return taskService.getVariable(taskId, variableName);  
  202.     }  
  203.       
  204.     /** 
  205.      * 获取指定用户名字的任务 
  206.      * @param userName 
  207.      * @return 
  208.      */  
  209.     public List<Task> findPersonalTasks(String userName){  
  210.         return taskService.findPersonalTasks(userName);  
  211.     }  
  212.       
  213.     /** 
  214.      * 根据任务id获取任务 
  215.      * @param taskId 
  216.      * @return 
  217.      */  
  218.     public Task getTask(String taskId) {  
  219.         return taskService.getTask(taskId);  
  220.           
  221.     }  
  222.       
  223.       
  224.   
  225.     /** 
  226.      * 级联删除流程定义,直接删除该流程定义下的所有实例 
  227.      *  
  228.      * @param deploymentId  流程定义id 
  229.      */  
  230.     public void deleteDeploymentCascade(String deploymentId) {  
  231.         repositoryService.deleteDeploymentCascade(deploymentId);  
  232.     }  
  233.   
  234.       
  235.   
  236.       
  237.   
  238.       
  239.   
  240. }  

 

 

   完整的application.xml:

 

  

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.      xmlns:p="http://www.springframework.org/schema/p"  
  6.     xmlns:aop="http://www.springframework.org/schema/aop"   
  7.     xmlns:tx="http://www.springframework.org/schema/tx"  
  8.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  9.            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  10.            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  11.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  12.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  13.   
  14.   
  15.     <!-- 配置数据源,导入c3p0-0.9.1.2.jar-->  
  16.     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  
  17.         destroy-method="close">  
  18.         <property name="driverClass">  
  19.             <value>net.sourceforge.jtds.jdbc.Driver</value>  
  20.         </property>  
  21.         <property name="jdbcUrl">  
  22.             <value>jdbc:jtds:sqlserver://localhost:1433;DatabaseName=jBPM</value>  
  23.         </property>  
  24.         <property name="user">  
  25.             <value>sa</value>  
  26.         </property>  
  27.         <property name="password">  
  28.             <value>123</value>  
  29.         </property>  
  30.   
  31.     </bean>  
  32.       
  33.     <bean name="hibernateProperties"  
  34.         class="org.springframework.beans.factory.config.PropertiesFactoryBean">  
  35.         <property name="properties">  
  36.             <props>  
  37.                   
  38.                 <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>  
  39.                 <prop key="hibernate.show_sql">true</prop>  
  40.                 <prop key="hibernate.hbm2ddl.auto">update</prop>   
  41.   
  42.             </props>  
  43.         </property>  
  44.     </bean>  
  45.       
  46.     <!-- spring集成hibernate配置 -->  
  47.     <bean id="sessionFactory"  
  48.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  49.         <property name="dataSource" ref="dataSource" />  
  50.         <property name="hibernateProperties" ref="hibernateProperties" />  
  51.         <property name="mappingLocations">  
  52.             <list>  
  53.                 <value>classpath*:com/ht/entity/*.hbm.xml</value>  
  54.                 <!-- 以下几个jbpm.*.hbm.xml由jBPM自带 -->  
  55.                 <value>classpath:jbpm.repository.hbm.xml</value>     
  56.                 <value>classpath:jbpm.execution.hbm.xml</value>     
  57.                 <value>classpath:jbpm.history.hbm.xml</value>     
  58.                 <value>classpath:jbpm.task.hbm.xml</value>     
  59.                 <value>classpath:jbpm.identity.hbm.xml</value>   
  60.             </list>  
  61.         </property>  
  62.     </bean>  
  63.       
  64.       
  65.   
  66.     <!-- jbpm配置 -->  
  67.     <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />  
  68.     <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine"  />  
  69.       
  70.     <bean id="jBPMUtil" class="com.ht.util.JBPMUtil">  
  71.         <property name="processEngine" ref="processEngine"></property>  
  72.     </bean>  
  73.       
  74.       
  75.   
  76.     <!-- 事务配置 -->  
  77.     <bean id="transactionManager"  
  78.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  79.         <property name="sessionFactory" ref="sessionFactory" />  
  80.     </bean>  
  81.   
  82. </beans>  

 

 

 

   当然其他的配置还是比较多的。大家可以参照我前一篇文章。

 

   ok.基本就是这样。具体的大家可以直接看项目

   运行环境:myeclipse8.5+jBPM4.4+jdk1.6+sql server 2000(貌似网上没找到这种建表语句。所以我也上传了)。

                  其他的主要建表语句在\install\src\db下面。

 

   比较大,jar包都没有放的。

  • jBPM4.4库表_sqlserver2000_.rar (4.6 KB)
  • 描述: jBPM4.4自带的18张表
  • 下载次数: 366
  • leave.rar (371 Bytes)
  • 描述: 这个实例中用到的2张库表
  • 下载次数: 431
  • jBPM4.4_ssh.rar (75.8 KB)
  • 下载次数: 731
转载至http://hellotommy.iteye.com/blog/804233
原创粉丝点击