jbpm

http://koudai.360.cn/u/23733528/article_217962180.html?s=y

经过一段事件的摸索终于将jpbm与spring完全整合,主要是事务处理的整合,工作流代码与业务代码在一个事务上下文进行;

使用了springmodules的封装,对jbpm稍有修改,稍后附上解决办法及代码;
========================================================

spring modules中包含了spring集成JBPM的机制,在使用的发现其并没有彻底解决两者的事务处理统一的问题,经过一段事件的摸索终于将jpbm与spring完全整合,主要是事务处理的整合,工作流代码与业务代码在一个事务上下文进行;
使用了springmodules的封装,对jbpm稍有修改,稍后附上解决办法及代码;
-------------------------------------------------姗姗来吃---------------o(∩_∩)o...哈哈,害得帖子被隐藏了
第一步:首先引入spring-modules-jbpm31.jar,同时将jbpm包含的所有hibernate映射文件解压出来,集成到spring配置文件中,可以使用类路径下的目录形式简化,如下:


--------------------------------------------------------------------------------

经测试在这种方式在weblogic上不能正常加载,从jar包加载也有问题必须解压到目录;

第二步:配置JPBM的大字段处理类型,这一步估计大家都知道,没什么说的;
xml 代码
<bean
id="jbpmTypes"
class="org.springframework.orm.hibernate3.TypeDefinitionBean">

--------------------------------------------------------------------------------

<bean
id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

--------------------------------------------------------------------------------

第三步:配置spring modules,通过 springmodules 初始化jbpmConfiguration;
xml 代码
Xml代码
<!-- jBPM configuration-->
<bean id="jbpmConfiguration"
class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory" />

<property name="configuration" value="classpath:/conf/jbpm.cfg.xml" />

<!--<property name="configuration" value="classpath:/org/jbpm/default.jbpm.cfg.xml" />-->
<!--<property name="processDefinitions">-->
<!--<list>-->
<!--<ref local="demoWorkflow" />-->
<!--</list>-->
<!--</property>-->

<!--<property name="createSchema" value="true"/>-->
</bean> <!-- jBPM configuration-->
<bean id="jbpmConfiguration"
class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory" />
<property name="configuration" value="classpath:/conf/jbpm.cfg.xml" />
<!--<property name="configuration" value="classpath:/org/jbpm/default.jbpm.cfg.xml" />-->
<!--<property name="processDefinitions">-->
<!--<list>-->
<!--<ref local="demoWorkflow" />-->
<!--</list>-->
<!--</property>-->
<!--<property name="createSchema" value="true"/>-->

--------------------------------------------------------------------------------
<!--<service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />-->
<service name="persistence">
<factory>
<bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<field name="isTransactionEnabled">
<STRONG><U><false /></U></STRONG>
</field>
<field name="isCurrentSessionEnabled">
<U><STRONG><true /></STRONG></U>
</field>
</bean>
</factory>
</service>

<service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
<service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
<service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
<service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
</jbpm-context>

<STRONG><U><!--<string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />--></U></STRONG>

<string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
<string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
<string name="resource.converter" value="org/jbpm/db/hibernate/jbpm.converter.properties" />
<string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
<string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
<string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
<string name="resource.varmapping" value="org/jbpm/context/exe/jbpm.varmapping.xml" />

<long name="jbpm.msg.wait.timout" value="5000" singleton="true" />
<int name="jbpm.byte.block.size" value="1024" singleton="true" />
<string name="mail.smtp.host" value="localhost" />
<bean name="jbpm.task.instance.factory" class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl"
singleton="true" />
<bean name="jbpm.variable.resolver" class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true" />
<bean name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />

</jbpm-configuration> <jbpm-configuration>
<jbpm-context>
<!--<service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />-->
<service name="persistence">
<factory>
<bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<field name="isTransactionEnabled">
<false />
</field>
<field name="isCurrentSessionEnabled">
<true />
</field>
</bean>
</factory>
</service>
<service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
<service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
<service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
<service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
</jbpm-context>
<!--<string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />-->
<string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
<string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
<string name="resource.converter" value="org/jbpm/db/hibernate/jbpm.converter.properties" />
<string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
<string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
<string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
<string name="resource.varmapping" value="org/jbpm/context/exe/jbpm.varmapping.xml" />
<long name="jbpm.msg.wait.timout" value="5000" singleton="true" />
<int name="jbpm.byte.block.size" value="1024" singleton="true" />
<string name="mail.smtp.host" value="localhost" />
<bean name="jbpm.task.instance.factory" class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl"
singleton="true" />
<bean name="jbpm.variable.resolver" class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true" />
<bean name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />
</jbpm-configuration>

第四步:修改JBPM自带的过滤器(web.xml),初始化当前请求线程的JBPM Context时从spring获取我们上面配置的jbpmConfiguration;其自带过滤器是通过JbpmConfiguration.getInstance获取的,不能公用spring事务上下文的hibernate session;

--------------------------------------------------------------------------------

import com.**.**.core.container.ApplicationContext;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.Serializable;
import java.security.Principal;
public
class JbpmContextHolder implements Filter, Serializable {
private
static
final
long serialVersionUID = 1L;
String jbpmConfigurationResource = null;
String jbpmContextName = null;
boolean isAuthenticationEnabled = true;
public
void init(FilterConfig filterConfig) throws ServletException {
// get the jbpm configuration resource
this.jbpmConfigurationResource = filterConfig.getInitParameter("jbpm.configuration.resource");
// get the jbpm context to be used from the jbpm configuration
this.jbpmContextName = filterConfig.getInitParameter("jbpm.context.name");
if (jbpmContextName == null) {
jbpmContextName = JbpmContext.DEFAULT_JBPM_CONTEXT_NAME;
}
// see if authentication is turned off
String isAuthenticationEnabledText = filterConfig.getInitParameter("authentication");
if ((isAuthenticationEnabledText != null)
&& ("disabled".equalsIgnoreCase(isAuthenticationEnabledText))
) {
isAuthenticationEnabled = false;
}
}
public
void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String actorId = null;
// see if we can get the authenticated swimlaneActorId
if (servletRequest instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
Principal userPrincipal = httpServletRequest.getUserPrincipal();
if (userPrincipal != null) {
actorId = userPrincipal.getName();
}
}
JbpmContext jbpmContext = getJbpmConfiguration().createJbpmContext(jbpmContextName);
try {
if (isAuthenticationEnabled) {
jbpmContext.setActorId(actorId);
}
filterChain.doFilter(servletRequest, servletResponse);
} finally {
jbpmContext.close();
}
}
注意:下面是修改后的方法,从spring获取JbpmConfiguration;
ApplicationContext是我们对spring的封装,可以改成自己的bean加载方式;


protected JbpmConfiguration getJbpmConfiguration() {
return (JbpmConfiguration) ApplicationContext.getInstance().getBizComponent("jbpmConfiguration");
}
public
void destroy() {
}
}

大功告成:

经过上边的修改后,从spring事务过程中调用JBPM方法、或者spring modules的方法时都会直接纳入当前事务,实现一致的提交和回滚;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值