其实很简单,跟着我做吧!
前提,jbpm的表和业务表都放在一个用户里面,这样可以共用一个sessionFactory,否则要用到分布式事务。
准备工作
0,拷贝jbpm-3.1.4.jar,jbpm-identity-3.1.4.jar, spring-modules-jbpm31.jar
到lib中。
从jbpm-3.1.4.jar 中解开default.jbpm.cfg.xml文件,并修改
<jbpm-context>
成
<jbpm-context name= "default.jbpm.context">
改名为jbpm.cfg.xml。
放到lib下。估计放classes下也可以,没有时间试。
1,集成jbpm 的hbm文件,红色是新加的。
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/juyee/mp/hbm</value>
</list>
</property>
<property name="mappingJarLocations">
<list>
<value>classpath*:jbpm-3.1.4.jar</value>
<value>classpath*:jbpm-identity-3.1.4.jar</value>
</list>
</property>
2,配置jbpm相关的service。
<bean id="jbpmConfiguration"
class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactoryBean"/>
<property name="configuration" value="classpath:jbpm.cfg.xml"/>
</bean>
<bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
<constructor-arg index="0" ref="jbpmConfiguration"/>
</bean>
<!--上面的template是不是看起来不爽,Hibernate 的service好像没有这个东西,
但没有办法,不加不行!
-->
<bean id="jbpmService" parent="proxyFactoryBean">
<property name="target">
<bean class="com.juyee.mp.service.JbpmService">
<property name="template">
<ref bean="jbpmTemplate"/>
<!--注意了,不是注入jbpmConfiguration -->
</property>
</bean>
</property>
</bean>
3,JbpmService是什么样子呢?
public class JbpmService extends JbpmDaoSupport
{
public ProcessInstance findProcessInstance(final Long processInstanceId)
{
return getTemplate().findProcessInstance(processInstanceId);
}
/**
* @see org.springmodules.workflow.jbpm31.JbpmOperations#findProcessInstances()
*/
public List findProcessInstances()
{
return getTemplate().findProcessInstances();
}
//复杂一点的例子
public void saveWorkFlowDefinition(String xmlStr)
{
final ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(xmlStr);
//call spring jbpm call back for save processdefinition
getTemplate().execute(new JbpmCallback()
{
public Object doInJbpm(JbpmContext jbpmContext) throws JbpmException
{
GraphSession gSession = jbpmContext.getGraphSession();
gSession.saveProcessDefinition(processDefinition);
return processDefinition;
}
});
}
....
}
大功告成!