Jbpm4与Spring整合配置过程
- 说明一下:hibernate还是由jbpm控制,没有让spring控制。与网上的jbpm+spring有所不同。(http://kb.cnblogs.com/b/294114/)
- 如何配置jbpm4请访问http://chengzhi-hong.javaeye.com/blog/542550 或 http://www.blogjava.net/pengo/archive/2009/12/04/304718.html?opt=admin也可以下载http://www.family168.com/ 网站中翻译的jbpm用户手册也是不错的入门书。
- 在项目中加入spring.jar包在src下面新建log4j.properties文件
-
log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= >>>>>>>LOG4J<<<<<<< %r %d [%t] %-p %c %x - #%l# - %m%nlog4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=auction.log
log4j.appender.logfile.MaxFileSize=512KB
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern= >>>>>>>LOG4J<<<<<<< %r %d %p [%c] - %m%n - 在src目录下面新建文件applicationContext.xml
-
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans default-lazy-init="false">
<bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">
<constructor-arg>
<value>jbpm.cfg.xml</value>
</constructor-arg>
</bean>
<bean id="processEngine" factory-bean="jbpmConfiguration"
factory-method="buildProcessEngine" />
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<bean id="executionService" factory-bean="processEngine"
factory-method="getExecutionService" />
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService"/>
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService"/>
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService"/>
</beans> - 修改jbpm.cfg.xml文件
-
jbpm.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.default.cfg.xml" />
<import resource="jbpm.spring.cfg.xml"/>
<import resource="jbpm.jpdl.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
<import resource="jbpm.tx.hibernate.cfg.xml" />
<import resource="jbpm.businesscalendar.cfg.xml" />
</jbpm-configuration> - 注意一下jbpm.cfg.xml文件中的jbpm.spring.cfg.xml引用这个文件就是把jbpm原有的机制改变成spring机制。还有jbpm.tx.hibernate.cfg.xml是jbpm应以控制hibernate而不是由spring去管理.
- 在src项目中新建文件jbpm.spring.cfg.xml
-
jbpm.spring.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<process-engine-context>
<command-service>
<retry-interceptor />
<environment-interceptor />
<spring-transaction-interceptor />
</command-service>
</process-engine-context>
<transaction-context>
<transaction />
<hibernate-session />
</transaction-context>
</jbpm-configuration> - 最后调用jbpm代码如下
-
jbpm调用类
public class JbpmControl {
private SpringConfiguration configuration = null;
private ProcessEngine processEngine = null;
private ExecutionService executionService = null;
private RepositoryService repositoryService = null;
private TaskService taskService = null;
private HistoryService historyService = null;
private ManagementService managementService = null;
public JbpmControl() {
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
configuration=(SpringConfiguration)applicationContext.getBean("jbpmConfiguration");
processEngine = (ProcessEngine)applicationContext.getBean("processEngine");
executionService = (ExecutionService)applicationContext.getBean("executionService");
repositoryService = (RepositoryService)applicationContext.getBean("repositoryService");
taskService = (TaskService)applicationContext.getBean("taskService");
historyService = (HistoryService)applicationContext.getBean("historyService");
managementService = (ManagementService)applicationContext.getBean("managementService");
}
}