Jbpm4.4 与spring集成

注:实现的过程中,一开始Spring的版本采用的是3.0.1的集成测试的时候会报:

tried to access method org.springframework.orm.hibernate3.SessionFactoryBuil......
的异常信息,最后改为2.5的版本即可。

  1. jbpm的配置
  2. <?xml version="1.0" encoding="UTF-8"?>
    
    <jbpm-configuration>
    
      <import resource="jbpm.default.cfg.xml" />
      <import resource="jbpm.businesscalendar.cfg.xml" />
      <!--
      	jbpm 与spring集成时,需要将事务管理交给spring 
      	<import resource="jbpm.tx.hibernate.cfg.xml" /> 
      -->
      <import resource="jbpm.tx.spring.cfg.xml" />
      
      <import resource="jbpm.jpdl.cfg.xml" />
      <import resource="jbpm.bpmn.cfg.xml" />
      <import resource="jbpm.identity.cfg.xml" />
    
      <!-- Job executor is excluded for running the example test cases. -->
      <!-- To enable timers and messages in production use, this should be included. -->
      <!--
      <import resource="jbpm.jobexecutor.cfg.xml" />
      -->
    
    </jbpm-configuration>

  3. Spring的配置
    <?xml version="1.0" encoding="UTF-8"?>
    
    <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: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">
    
      <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
           <property name="jbpmCfg" value="jbpm.cfg.xml"></property>
      </bean>
    
      <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
    
      <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/jbpm" />
        <property name="username" value="root" />
        <property name="password" value="162838" />
      </bean>
      
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name = "hibernateProperties" >
        	<props >
                  <prop key = "hibernate.dialect" > org.hibernate.dialect.MySQLInnoDBDialect </prop >
                  <prop key = "hibernate.show_sql" > true </prop >
                  <prop key = "hibernate.format_sql" > true </prop >
                  <prop key = "hibernate.hbm2ddl.auto" > update </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>
    
      <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
        <property name="dataSource" ref="dataSource" />
      </bean>
    </beans>
  4. 测试
    @Test
        public void testSpring(){
            try {
                ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
                ProcessEngine pe = (ProcessEngine) ac.getBean("processEngine");
                HistoryService hs = pe.getHistoryService();
                //查看系统中定义的流程的历史流程实例信息
                List<HistoryProcessInstance> hpis = hs.createHistoryProcessInstanceQuery().processDefinitionId("demo-1").list();
                for (HistoryProcessInstance historyProcessInstance : hpis) {
                    System.out.println(historyProcessInstance.getProcessInstanceId());
                }
            } catch (BeansException e) {
                e.printStackTrace();
            }
        }
  5. 测试结果 控制台输出信息
    log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
    log4j:WARN Please initialize the log4j system properly.
    15:28:59,070 FIN | [WireContext] eagerly initializing org.jbpm.pvm.internal.id.DatabaseIdComposer
    Hibernate: 
        select
            propertyim0_.KEY_ as KEY1_14_,
            propertyim0_.VERSION_ as VERSION2_14_,
            propertyim0_.VALUE_ as VALUE3_14_ 
        from
            JBPM4_PROPERTY propertyim0_ limit ?
    Hibernate: 
        select
            propertyim0_.KEY_ as KEY1_14_0_,
            propertyim0_.VERSION_ as VERSION2_14_0_,
            propertyim0_.VALUE_ as VALUE3_14_0_ 
        from
            JBPM4_PROPERTY propertyim0_ 
        where
            propertyim0_.KEY_=?
    15:29:05,282 INF | [CheckDbCmd] jBPM version info: library[4.4-SNAPSHOT], schema[null]
    Hibernate: 
        select
            historypro0_.DBID_ as DBID1_4_,
            historypro0_.DBVERSION_ as DBVERSION2_4_,
            historypro0_.ID_ as ID3_4_,
            historypro0_.PROCDEFID_ as PROCDEFID4_4_,
            historypro0_.KEY_ as KEY5_4_,
            historypro0_.START_ as START6_4_,
            historypro0_.END_ as END7_4_,
            historypro0_.DURATION_ as DURATION8_4_,
            historypro0_.STATE_ as STATE9_4_,
            historypro0_.ENDACTIVITY_ as ENDACTI10_4_,
            historypro0_.NEXTIDX_ as NEXTIDX11_4_ 
        from
            JBPM4_HIST_PROCINST historypro0_ 
        where
            historypro0_.PROCDEFID_='demo-1'
    
    //历史流程实例的ID信息
    demo.60007
    demo.70001
    demo.80001

你可能感兴趣的:(spring,jbpm)