jbpm4.0整合spring+hibernate

    首先加入jbpm4.0相关jar包。

 

    修改jbpm.spring.default.cfg.xml 注释掉以下部分(让jbpm 的session-factory失效)

<hibernate-configuration>
      <cfg resource="jbpm.hibernate.cfg.xml" />
</hibernate-configuration>

<hibernate-session-factory />

     

    建立一个ProcessEngineFactoryBean类(用来初始化JBPM4的相关配置文件、工作流引擎,并且把sessionFactory的创建交给spring的容器)

   

package com.rich.oa.jbpm;

import org.hibernate.SessionFactory;

import org.jbpm.api.ProcessEngine;

import org.jbpm.pvm.internal.cfg.SpringConfiguration;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


public class ProcessEngineFactoryBean implements FactoryBean,
    InitializingBean, DisposableBean, ApplicationContextAware {
    private String jbpmConfigurationLocation = "jbpm.cfg.xml";
    private SessionFactory sessionFactory;
    private ApplicationContext applicationContext;
    private ProcessEngine processEngine;

    public Object getObject() throws Exception {
        return processEngine;
    }

    @SuppressWarnings("unchecked")
    public Class getObjectType() {
        return ProcessEngine.class;
    }

    public boolean isSingleton() {
        return true;
    }

    public void afterPropertiesSet() {
        SpringConfiguration cfg = new SpringConfiguration(jbpmConfigurationLocation);
        cfg.setApplicationContext(applicationContext);

        cfg.setSessionFactory(sessionFactory);
        this.processEngine = cfg.buildProcessEngine();
    }

    public void destroy() {
        this.processEngine = null;
        this.sessionFactory = null;
    }

    public void setJbpmConfigurationLocation(
        String jbpmConfigurationLocation) {
        this.jbpmConfigurationLocation = jbpmConfigurationLocation;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public void setApplicationContext(
        ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}

  

   并且在Spring配置文件中加入如下配置:

  

<bean id="processEngine" class="com.rich.oa.jbpm.ProcessEngineFactoryBean">
	<property name="sessionFactory" ref="sessionFactory" />
</bean>

 

    

    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
    <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />

 

   添加JBPM4的服务到spring IOC容器中错误:
   注意:所有的jbpm4的配置文件必须在src目录下,并且不能有独立的目录,因为在初始化发布流程的代码中
ProcessEngine processEngine = new Configuration().buildProcessEngine();
因为JbpmConfiguration extends Configuration implements Context, ProcessEngine, EnvironmentFactory  因此会
调用JbpmConfiguration类中buildProcessEngine()方法来创建ProcessEngine来得到JBPM4的服务,在这个方法中,有这样一段代码

   

if (!isConfigured) {
      setResource("jbpm.cfg.xml");
    }

 
    
   它会去src下找jbpm.cfg.xml文件,如果配置文件不在src目录下,那么就会找不到配置文件(jbpm.cfg.xml)

 

   加入JBPM4的实体关系映射文件:

  

<property name="mappingLocations">
            <list>
                <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.jpdl.hbm.xml</value>
                <value>classpath*:jbpm.identity.hbm.xml</value>
            </list>
</property>

 

  改写Jbpm4中的jbpm.tx.hibernate.cfg.xml的配置,主要是修改processEngine 这个bean里的sessionFactory.从而再加上上面这种方式来进行事务的管理。

   

<jbpm-configuration>

	<process-engine-context>
		<command-service>
			<retry-interceptor />
			<environment-interceptor />
			<spring-transaction-interceptor />
		</command-service>
	</process-engine-context>

	<transaction-context>
		<hibernate-session current="true" />
	</transaction-context>

</jbpm-configuration>

   修改 <standard-transaction-interceptor />为<spring-transaction-interceptor />
<hibernate-session /><transaction />为<hibernate-session current="true"/>
current="true"这个属性将强使jbpm搜索当前的spring提供的session。

  

   hibernateSessionFactory上配置上Jpbm的hbm.xml文件。如:

  

<property name="mappingLocations"> <list>
	<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.jpdl.hbm.xml</value>
                <value>classpath:jbpm.identity.hbm.xml</value></list>
</property>


   

   还需要在jbpm.default.cfg.xml中注释以下代码:

  

<!-- 
    <hibernate-configuration>
      <cfg resource="jbpm.hibernate.cfg.xml" />     
    </hibernate-configuration>

    <hibernate-session-factory />
-->

    

    ok,测试通过!

 

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值