【转】jbpm4.4与spring集成

下面是集成方法。

版本:
jbpm4.3
spring 3.0.2
mysql5.1.40

直接从jbpm4.4自带的文件到src目录:
从jbpm-4.4"install"src"cfg"hibernate"jdbc复制mysql.hibernate.cfg.xml到src目录,文件名改为hibernate.cfg.xml。
从jbpm-4.4"install"src"cfg"spring复制applicationContext.xml到src目录。
从jbpm-4.4"install"src"cfg"jbpm复制spring.jbpm.cfg.xml到src目录,文件名改为jbpm.cfg.xml。
修改applicationContext.xml、hibernate.cfg.xml的数据库配置信息,jbpm4.4与spring的集成就完成了,可以自己写测试文件测试,集成非常容易。

不过在applicationContext.xml和hibernate.cfg.xml两个文件都要改数据库信息有点麻烦,所以只复制 applicationContext.xml、spring.jbpm.cfg.xml两个文件到src目录,把hibernate.cfg.xml的配置整进spring的配置文件applicationContext.xml中。
applicationContext.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:p="http://www.springframework.org/schema/p"
  5.         xmlns:jee="http://www.springframework.org/schema/jee" 
  6.         xmlns:tx="http://www.springframework.org/schema/tx"
  7.         xmlns:context="http://www.springframework.org/schema/context" 
  8.         xmlns:aop="http://www.springframework.org/schema/aop"
  9.         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
  10.         default-lazy-init="true">
  11. <context:annotation-config />
  12. <bean
  13.   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
  14.   p:location="hibernate.properties"
  15.   p:ignoreUnresolvablePlaceholders="true" />
  16.   <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />
  17.   <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
  18.   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  19.     <property name="dataSource" ref="dataSource" />
  20.         <property name="mappingResources">
  21.                 <list>
  22.                         <value>jbpm.repository.hbm.xml</value>
  23.                         <value>jbpm.execution.hbm.xml</value>
  24.                         <value>jbpm.history.hbm.xml</value>
  25.                         <value>jbpm.task.hbm.xml</value>
  26.                         <value>jbpm.identity.hbm.xml</value>
  27.                 </list>
  28.         </property>
  29.         <property name="hibernateProperties">
  30.                 <props>
  31.                                 <prop key="hibernate.dialect">${dataSource.dialect}</prop>
  32.                                 <prop key="hibernate.hbm2ddl.auto">${dataSource.hbm2ddl.auto}</prop>
  33.                         </props>
  34.         </property>
  35.   </bean>
  36.   
  37.   <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  38.     <property name="sessionFactory" ref="sessionFactory" />
  39.     <property name="dataSource" ref="dataSource" />
  40.   </bean>
  41.   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  42.     <property name="driverClassName" value="${dataSource.driverClassName}" />
  43.     <property name="url" value="${dataSource.url}" />
  44.     <property name="username" value="${dataSource.username}" />
  45.     <property name="password" value="${dataSource.password}" />
  46.   </bean>
  47. </beans>
复制代码

新建文件hibernate.properties,主要用来配置连接数据库信息

  1. dataSource.password=
  2. dataSource.username=root
  3. dataSource.databaseName=jbpmdb
  4. dataSource.driverClassName=com.mysql.jdbc.Driver
  5. dataSource.dialect=org.hibernate.dialect.MySQLInnoDBDialect
  6. dataSource.serverName=localhost:3306
  7. dataSource.url=jdbc:mysql://${dataSource.serverName}/${dataSource.databaseName}
  8. dataSource.properties=user=${dataSource.username};databaseName=${dataSource.databaseName};serverName=${dataSource.serverName};password=${dataSource.password}
  9. dataSource.hbm2ddl.auto=update
复制代码

以后要改数据库配置信息也只在这个文件修改就可以了。

测试用的流程swing.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<process name="swing" xmlns="http://jbpm.org/4.3/jpdl">
   <start g="94,64,48,48" name="start1">
      <transition g="-52,-22" name="A" to="A"/>
   </start>
   <task assignee="A" g="73,195,92,52" name="A">
      <transition g="-52,-22" name="B" to="B"/>
   </task>
   <task assignee="B" g="266,192,92,52" name="B">
      <transition g="-40,-21" name="end" to="end1"/>
   </task>
   <end g="290,327,48,48" name="end1"/>
</process>


测试代码
public class Main {
    public static void main(String[] args)  {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml";
        applicationContext.start();
        ProcessEngine processEngine = (ProcessEngine)applicationContext.getBean("processEngine";
        ExecutionService executionService = processEngine.getExecutionService();
        TaskService taskService = processEngine.getTaskService();

        //发布流程
        String deploymentId = processEngine.getRepositoryService().createDeployment()
        .addResourceFromClasspath("resource/swing.jpdl.xml".deploy();
        System.out.println("流程发布ID:"+deploymentId);
        
        //启动一个流程实例
        ProcessInstance processInstance = executionService.startProcessInstanceByKey("swing";
        System.out.println("流程实例ID:" + processInstance.getId());

        //A处理任务
        List<Task> taskList_A = taskService.findPersonalTasks("A";
        System.out.println("A待处理任务数:" + taskList_A.size());
        if(taskList_A.size() > 0){
            Task task = taskList_A.get(0);
            taskService.completeTask(task.getId());
        }
        
        //B处理任务
        List<Task> taskList_B = taskService.findPersonalTasks("B";
        System.out.println("B待处理任务数:" + taskList_B.size());
        if(taskList_B.size() > 0){
            Task task = taskList_B.get(0);
            taskService.completeTask(task.getId());
        }
        
    }
}


附件是完整的集成文件和测试代码,仅在spring2.5.6测试过,要运行该部分代码,需要添加jbpm4.4和spring的相关依赖库文件参照.classpath时行添加。

 

 

转自:http://bbs.chinaunix.net/thread-1754666-1-1.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值