posts - 59, comments - 244, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          jbpm4.3與spring集成

          Posted on 2010-01-04 23:54 penngo 閱讀(11147) 評論(13)  編輯  收藏 所屬分類: JBPM
          jbpm4.2與spring集成有點問題,直接跟據它自己的“開發指南”提供的方法是不能集成的。在官網查到的信息是發布4.2時,忘記更新集成spring的文件。不過4.3已經把該bug改過來了。下面是集成方法。

          版本:
          jbpm4.3
          spring2.5.6
          mysql5.1.40

          直接從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());
                  }
                  
              }
          }


          附件是完整的集成文件和測試代碼,僅在spring2.5.6測試過,要運行該部分代碼,需要添加jbpm4.3和spring的相關庫文件。
          源代碼:jbpm4.3-spring




          評論

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-01-05 08:45 by YagnL
          4.3的集成還是挺方便的

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-01-05 09:47 by pengo
          4.3集成spring很容易,主要是官方把這部分工作給我們做好了。

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-01-06 14:04 by 羅萊家紡官方網
          實力的方可打開了瘋狂

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-02-03 10:48 by
          我測試的時候B處理任務處會報錯 com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`udpf`.`jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))

          # re: jbpm4.3與spring集成[未登錄]  回復  更多評論   

          2010-03-26 11:07 by JK
          這樣配置從日志上看好像會加載兩個sessionfactory

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-04-08 14:17 by ff
          除了spring,那個jbpm4.3的jar包要加哪些

          # re: jbpm4.3與spring集成[未登錄]  回復  更多評論   

          2010-09-09 17:55 by colin
          WARNING: no objects were deployed! Check if you have configured a correct deployer in your jbpm.cfg.xml file for the type of deployment you want to do.
          這是什么原因 ?

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-09-25 12:25 by peerless
          @崔
          檢查一下用這個方言MySQLInnoDBDialect

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-12-13 12:36 by pandora jewelry
          其中hsqldb和hibernate都是從jbpm4.4的lib文件夾里面拷過去的aswe

          # re: jbpm4.3與spring集成  回復  更多評論   

          2010-12-13 12:37 by pandora jewelry
          其中hsqldb和hibernate都是從jbpm4.4的lib文件夾里面拷過去的

          # re: jbpm4.3與spring集成  回復  更多評論   

          2011-01-06 11:59 by achui
          能把你用到的包和代碼一起發給我嗎,我的郵箱是achui_1980@163.com,我用你的代碼測試,一直提示 Can't delete processInstance swing.7: no processInstance found for the given id,(在進入end節點的時候)

          # re: jbpm4.3與spring集成  回復  更多評論   

          2011-01-06 22:22 by pengo
          直接看你的報錯,好像不關包的問題。

          # re: jbpm4.3與spring集成[未登錄]  回復  更多評論   

          2012-04-28 17:21 by david
          Check if you have configured a correct deployer in your jbpm.cfg.xml file for the type of deployment you want to do


          碰到了相同的問題啊
          主站蜘蛛池模板: 漳平市| 嘉善县| 莱阳市| 上思县| 武陟县| 封开县| 金昌市| 巴青县| 宣汉县| 石城县| 修武县| 濉溪县| 睢宁县| 德昌县| 即墨市| 芮城县| 北碚区| 涞水县| 甘洛县| 定州市| 黄石市| 敦煌市| 宁国市| 新兴县| 芷江| 唐海县| 徐州市| 明光市| 北海市| 呈贡县| 武威市| 平安县| 天祝| 阿克陶县| 维西| 江北区| 资阳市| 阳新县| 龙口市| 襄汾县| 延安市|