jbpm4GA发布已有一个月了,作为jbpm的新手,发现关于jbpm4的资源太稀少了,本人把jbpm4与spring的整合过程发布一下。本人使用struts2+hibernate+spring整合环境。
jBPM4.0整合步骤如下:
● 在WEB-INF\lib目录下增加jbpm.jar
● 在applicationContext.xml的sessionFactorybean中增加属性:
<property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
●首先建立配置文件jbpm.hibernate.cfg.xml,放到src下:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/OA</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.format_sql">false</property>
<mapping resource="jbpm.repository.hbm.xml" />
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
<mapping resource="jbpm.identity.hbm.xml" />
</session-factory>
</hibernate-configuration>
● 在applicationContext.xml的中增加bean引入sessionFactory:
<bean id="processEngine" class="org.shb.wfm.workflow.ProcessEngineFactoryBean">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
●书写一个ProcessEngineFactoryBean类,主要代码如下:
public void afterPropertiesSet() {
SpringConfiguration cfg = new SpringConfiguration(jbpmConfigurationLocation);
cfg.setApplicationContext(applicationContext);
cfg.setSessionFactory(sessionFactory);
this.processEngine = cfg.buildProcessEngine();
}
这里主要是创建流程引擎,以提供使用者在service层中调用。
●把jbpm.default.cfg.xml中的下面代码注释掉:
<hibernate-configuration>
<cfg resource="jbpm.hibernate.cfg.xml" />
</hibernate-configuration>
<hibernate-session-factory />
● 其次建立配置文件jbpm.cfg.xml,放到config目录下:
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.default.cfg.xml" />
<import resource="jbpm.tx.hibernate.cfg.xml" />
<import resource="jbpm.jpdl.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
</jbpm-configuration>
这样,jBPM4.0就整合好了
在处理方法中添加:
ProcessEngine processEngine = jbpmConfiguration.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
String deploymentId = repositoryService.createDeployment()
.addResourceFromClasspath("****.jpdl.xml").deploy();
repositoryService.deleteDeployment(deploymentId);
这里的****是需要发布的jbpm流程文件名。
本文参考 http://www.iteye.com/topic/416883对原配置做了修改,以免重复创建的sessionFactory。
很简单的配置,水平有限,各位不要拍砖。
jBPM4.0整合步骤如下:
● 在WEB-INF\lib目录下增加jbpm.jar
● 在applicationContext.xml的sessionFactorybean中增加属性:
<property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
●首先建立配置文件jbpm.hibernate.cfg.xml,放到src下:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/OA</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.format_sql">false</property>
<mapping resource="jbpm.repository.hbm.xml" />
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
<mapping resource="jbpm.identity.hbm.xml" />
</session-factory>
</hibernate-configuration>
● 在applicationContext.xml的中增加bean引入sessionFactory:
<bean id="processEngine" class="org.shb.wfm.workflow.ProcessEngineFactoryBean">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
●书写一个ProcessEngineFactoryBean类,主要代码如下:
public void afterPropertiesSet() {
SpringConfiguration cfg = new SpringConfiguration(jbpmConfigurationLocation);
cfg.setApplicationContext(applicationContext);
cfg.setSessionFactory(sessionFactory);
this.processEngine = cfg.buildProcessEngine();
}
这里主要是创建流程引擎,以提供使用者在service层中调用。
●把jbpm.default.cfg.xml中的下面代码注释掉:
<hibernate-configuration>
<cfg resource="jbpm.hibernate.cfg.xml" />
</hibernate-configuration>
<hibernate-session-factory />
● 其次建立配置文件jbpm.cfg.xml,放到config目录下:
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.default.cfg.xml" />
<import resource="jbpm.tx.hibernate.cfg.xml" />
<import resource="jbpm.jpdl.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
</jbpm-configuration>
这样,jBPM4.0就整合好了
在处理方法中添加:
ProcessEngine processEngine = jbpmConfiguration.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
String deploymentId = repositoryService.createDeployment()
.addResourceFromClasspath("****.jpdl.xml").deploy();
repositoryService.deleteDeployment(deploymentId);
这里的****是需要发布的jbpm流程文件名。
本文参考 http://www.iteye.com/topic/416883对原配置做了修改,以免重复创建的sessionFactory。
很简单的配置,水平有限,各位不要拍砖。