前段时间用jbpm做了个项目,花了很多时间来处理和spring的事务整合,找了很多资料都不是很全,贴段代码,希望对大家有帮助。
jbpm.cfg.xml文件这个地方改一下,关掉jbpm事务:
Xml代码
<service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<factory>
<bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<field name="isTransactionEnabled"><false/></field>
<field name="isCurrentSessionEnabled"><true/></field>
</bean>
</factory>
</service>
spring配置文件:
Xml代码
<bean id="jbpmConfiguration" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory" />
<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>
<bean id="applyDao" parent="txProxyTemplate">
<property name="target">
<bean class="com.hljt.daos.impl.ApplyDaoImpl">
<property name="jbpmTemplate">
<ref bean="jbpmTemplate" />
</property>
</bean>
</property>
</bean>
由于springmodules里面封装的方法很少,很多方法需要接口回调(估计是叫这个我对这些名词不太了解),举个例子:
Java代码
private JbpmTemplate jbpmTemplate;
public void save(final TbApply apply,TbUser user) {
this.jbpmTemplate.execute(new JbpmCallback(){
public Object doInJbpm(JbpmContext context)throws JbpmException {
ProcessDefinition pd = context.getGraphSession().findLatestProcessDefinition("apply");
ProcessInstance pi = pd.createProcessInstance();
pi.getContextInstance().setVariable("issueUser",
apply.getTbuser().getName());
TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
ti.setActorId(apply.getTbuser().getName());
ti.setVariable("applyId", apply.getId());
ti.end();
context.save(pi);
return null;
}
});
}
原帖地址:http://jbpm.group.iteye.com/group/topic/7091
jbpm.cfg.xml文件这个地方改一下,关掉jbpm事务:
Xml代码
<service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<factory>
<bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<field name="isTransactionEnabled"><false/></field>
<field name="isCurrentSessionEnabled"><true/></field>
</bean>
</factory>
</service>
spring配置文件:
Xml代码
<bean id="jbpmConfiguration" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory" />
<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>
<bean id="applyDao" parent="txProxyTemplate">
<property name="target">
<bean class="com.hljt.daos.impl.ApplyDaoImpl">
<property name="jbpmTemplate">
<ref bean="jbpmTemplate" />
</property>
</bean>
</property>
</bean>
由于springmodules里面封装的方法很少,很多方法需要接口回调(估计是叫这个我对这些名词不太了解),举个例子:
Java代码
private JbpmTemplate jbpmTemplate;
public void save(final TbApply apply,TbUser user) {
this.jbpmTemplate.execute(new JbpmCallback(){
public Object doInJbpm(JbpmContext context)throws JbpmException {
ProcessDefinition pd = context.getGraphSession().findLatestProcessDefinition("apply");
ProcessInstance pi = pd.createProcessInstance();
pi.getContextInstance().setVariable("issueUser",
apply.getTbuser().getName());
TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
ti.setActorId(apply.getTbuser().getName());
ti.setVariable("applyId", apply.getId());
ti.end();
context.save(pi);
return null;
}
});
}
原帖地址:http://jbpm.group.iteye.com/group/topic/7091