jbpm 4.4 与 spring 集成

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

不过在applicationContext.xml和hibernate.cfg.xml两个文件都要改数据库信息有点麻烦,所以只复制applicationContext.xml、spring.jbpm.cfg.xml两个文件到src目录,把hibernate.cfg.xml的配置整进spring的配置文件applicationContext.xml中。
applicationContext.xml

< beans  xmlns ="http://www.springframework.org/schema/beans"  
         xmlns:aop
="http://www.springframework.org/schema/aop"  
         xmlns:context
="http://www.springframework.org/schema/context"
          xmlns:p
="http://www.springframework.org/schema/p"
         xmlns:tx
="http://www.springframework.org/schema/tx"
       xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation
="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
>
 
 
< context:annotation-config  />

< bean
  
class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
  p:location
="hibernate.properties"
  p:ignoreUnresolvablePlaceholders
="true"   />
  
< bean  id ="springHelper"  class ="org.jbpm.pvm.internal.processengine.SpringHelper"   />
  
< bean  id ="processEngine"  factory-bean ="springHelper"  factory-method ="createProcessEngine"   />
  
< bean  id ="sessionFactory"  class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
    
< property  name ="dataSource"  ref ="dataSource"   />
    
< property  name ="mappingResources" >
        
< list >
            
< value > jbpm.repository.hbm.xml </ value >
            
< value > jbpm.execution.hbm.xml </ value >
            
< value > jbpm.history.hbm.xml </ value >
            
< value > jbpm.task.hbm.xml </ value >
            
< value > jbpm.identity.hbm.xml </ value >
        
</ list >
    
</ property >
    
< property  name ="hibernateProperties" >
        
< props >
                
< prop  key ="hibernate.dialect" > ${dataSource.dialect} </ prop >
                
< prop  key ="hibernate.hbm2ddl.auto" > ${dataSource.hbm2ddl.auto} </ prop >
            
</ props >
    
</ property >
  
</ bean >
  
< bean  id ="transactionManager"  class ="org.springframework.orm.hibernate3.HibernateTransactionManager" >
    
< property  name ="sessionFactory"  ref ="sessionFactory"   />
    
< property  name ="dataSource"  ref ="dataSource"   />
  
</ bean >
  
< bean  id ="dataSource"  class ="org.springframework.jdbc.datasource.DriverManagerDataSource" >
    
< property  name ="driverClassName"  value ="${dataSource.driverClassName}"   />
    
< property  name ="url"  value ="${dataSource.url}"   />
    
< property  name ="username"  value ="${dataSource.username}"   />
    
< property  name ="password"  value ="${dataSource.password}"   />
  
</ bean >
</ beans >


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

dataSource.password=123
dataSource.username=root
dataSource.databaseName=jbpmdb
dataSource.driverClassName=com.mysql.jdbc.Driver
dataSource.dialect=org.hibernate.dialect.MySQLInnoDBDialect
dataSource.serverName=localhost:3306
dataSource.url=jdbc:mysql://${dataSource.serverName}/${dataSource.databaseName}
dataSource.properties=user=${dataSource.username};databaseName=${dataSource.databaseName};serverName=${dataSource.serverName};password=${dataSource.password}
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());
        }
        
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值