jBPM是一个可扩展、灵活的能够实现工作流/业务流程管理的企业级开发框架,提供了流程定义、流程部署、流程执行、流程管理等功能。
jBPM的核心为processEngine, 通过processEngine获得各种service接口来对流程进行操作,所以jbpm与ssh整合,就是将processEngine交给spring进行管理。
核心代码:
<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" /> <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
SpringHelper源码:
public class SpringHelper implements ApplicationContextAware { protected ApplicationContext applicationContext; protected String jbpmCfg = "jbpm.cfg.xml"; public void setJbpmCfg(String jbpmCfg) { this.jbpmCfg = jbpmCfg; } public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } protected ProcessEngine createProcessEngine() { return new ConfigurationImpl() .springInitiated(applicationContext) .setResource(jbpmCfg) .buildProcessEngine(); } }
jbpm.cfg.xml代码:
<?xml version="1.0" encoding="UTF-8"?> <jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <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" /> <import resource="jbpm.console.cfg.xml" /> <process-engine-context> <string name="spring.cfg" value="classpath:/applicationContext.xml"/> </process-engine-context> </jbpm-configuration>
加载Spring配置文件时,如果Spring配置文件中所定义的Bean类实现了ApplicationContextAware 接口,那么在加载Spring配置文件时,会自动调用ApplicationContextAware 接口中的 public void setApplicationContext(ApplicationContext context) throws BeansException方法,获得ApplicationContext对象。前提必须在Spring配置文件中指定该类。