首先加入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,测试通过!
分享到:
相关推荐
JBPM5+Spring+Hibernate+MySQL 请假例子
jbpm4整合struts2+spring2.5+hibernate3.3.doc
jbpm4.0实例(整合spring2.5+ext3.0+hibernate)
参考网上例子和自己所学所编写的一个程序,时间仓促,部分功能为实现,仅供大家学习参考。攒点分数而已
Spring+hibernate4+SpringMVC+Jbpm4.4 。Jbpm 4.4 整合 spring,数据库是mysql,hibernate大版本是4。供以后参考使用
整合的jbpm4的spring、hibernate的网上的请假的例子。由于lib包太大,需要自己添加lib下的jar包
Jbpm+Spring+hibernate+struts2+mysql+c3p0项目部署
spring+struts+hibernate+jbpm+dwr整合开发的OA办公系统源码
spring+struts1+hibernate+jbpm实例
jbpm4整合struts2+spring2[1].5+hibernate3.3
在学习jbpm5的过程中,发现很难找到一个合适的,能跑的起来的,整合ssh的例子,之前在csdn上花费不少分下了好多个,能跑起来的好像就1个,不是jar包不匹配就是些其他的莫名奇妙的错误,对应刚刚接触jbpm的人来说,一...
spring+hibernate+jbpm详细整合文档
JBPM4.4+spring+ext整合
struts2+spring+hibernate+jbpm工作流实例 描述的是公文审批流转过程.
这是哥们做的毕业设计,是基于struts+spring+hibernate+jbpm的外贸服装企业的工作流系统
struts+hibernate+spring+jbpm 智能工作流系统(包含构建数据库脚本和项目脚本),部署即可
Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8整合 超级详细的文档,透彻讲解JBPM与SSH的整合过程
Struts+Hibernate+spring+jpa+lucene+jbpm+compass配置文件
OA办公自动化系统。Struts+Spring+Hibernate+Jbpm技术实现。 功能有系统管理包括:用户管理,部门管理,用户权限分配等;我的办公桌等