(1)model pojo 加载(在sessionFactory里加载):
记得加包:spring-modules-jbpm31.jar
<bean id=“sessionFactory” …….>
……….
<property name="mappingLocations">
<list>
<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
</list>
</property>
</bean>
(2)spring 管理的jbpm数据操作接口
<bean id=“jbpmConfiguration”
class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="configuration" value="classpath:jbpm.cfg.xml"/>
// jbpm.cfg.xml 文件路径在src下面
</bean>
<bean id=“jbpmTemplate” class="org.springmodules.workflow.jbpm31.JbpmTemplate">
<constructor-arg index="0" ref="jbpmConfiguration" />
</bean>
jbpmTmepate 与spring的JdbcTemplate有很想似之处。
(3)配置过滤器 JbpmContextFilter
<filter>
<filter-name>JbpmContextFilter</filter-name>
<filter-class>
com.jh.jcs.workflow.filter.JbpmContextFilter
</filter-class>
</filter>
package com.jh.jcs.workflow.filter;
import java.io.IOException;
import java.io.Serializable;
import java.security.Principal;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springmodules.workflow.jbpm31.JbpmTemplate;
import org.unitils.spring.SpringUnitils;
public class JbpmContextFilter implements Filter, Serializable {
private static final long serialVersionUID = 1L;
String jbpmConfigurationResource = null;
String jbpmContextName = null;
boolean isAuthenticationEnabled = true;
FilterConfig config;
public void setFilterConfig(FilterConfig config) {
this.config = config;
}
public FilterConfig getFilterConfig() {
return config;
}
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;
}
this.setFilterConfig(filterConfig);
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String actorId = null;
//通过filterconfig 得到servletcontext
ServletContext context = getFilterConfig().getServletContext();
// 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(context).createJbpmContext(jbpmContextName);
servletRequest.setAttribute("jbpmContext",jbpmContext);
try {
if (isAuthenticationEnabled) {
jbpmContext.setActorId(actorId);
}
filterChain.doFilter(servletRequest, servletResponse);
} finally {
if(jbpmContext!=null){
try{
if(jbpmContext.getSession().isOpen()){
jbpmContext.close();
}
}catch(Exception e){
e.printStackTrace();
}
jbpmContext = null;
}
}
}
protected JbpmConfiguration getJbpmConfiguration(ServletContext servletContext) {
JbpmTemplate jbpmTemplate = (JbpmTemplate) WebApplicationContextUtils
.getWebApplicationContext(servletContext).getBean(
"jbpmTemplate");
JbpmConfiguration jconfig = jbpmTemplate.getJbpmConfiguration();
//return (JbpmConfiguration)SpringUtil.getInstance().getBean("jbpmConfiguration");
return jconfig;
}
public void destroy() {
}
}
(4)使用1
@Autowired
@Qualifier("jbpmConfiguration")
JbpmConfiguration jbpmConfiguration;
public JbpmContext getJbpmContext() {
return jbpmConfiguration.getCurrentJbpmContext();
}
JbpmContext jbpmContext = getJbpmContext();
使用2
JbpmContext jbpmContext=ServletActionContext.getRequest().getAttribute("jbpmContext");
分享到:
相关推荐
大概整理jbpm4与ssh框架整合,如果大家整合使用有什么问题可以给我留言。
jbpm4.4+ssh整合还需要安装插件进入到myeclipse中 将相应的jar文件放进去 就能够运行 jbpm4.4 jar ssh(strut2,hibernate3,spring3)三大框架整合的jar包 例子是 请假流程 代码中有很好的注释 便于初学者学习
JBPM4与SSH三大框架整合的请假流程
JBPM4.4与SSH2之整合(附完整源码) 这些天,想着把jbpm4.4与ssh2整合一下,由于之前从来没用过jbpm,也不知道各版本之间会有什么差异(经过网上的收集对比,还真有些差异),整合起来,还真是有些步履艰难。收集了...
jBPM4.4+ssh 整合配置及完整实例
jBPM4.4与ssh整合,很好的入门例子
jbpm4.4与ssh框架的整合
有代码示例也有文档说明,适合学习JBPM的童鞋们上手
非常好的ssh jbpm整合,我花了三天参考了很多资料才整合出来的。下载下来直接导入就可以直接使用,非常方便。有什么问题可以联系我,嘿嘿
JBPM4.4与SSH2整合,网上找了很多资料,运行都会出问题,这个经过实验按照步骤操作绝对不会有问题的。祝你工作愉快!
jbpm整合ssh的例子.tomcat,mysql.jbpm整合ssh的例子.tomcat,mysql
这些天,想着把jbpm4.4与ssh2整合一下,由于之前从来没用过jbpm,也不知道各版本之间会有什么差异(经过网上的收集对比,还真有些差异),整合起来,还真是有些步履艰难。收集了不少别人的整合资料和源码,但是最终...
Jbpm工作流与ssh框架集成,开发实例
Jbpm4和ssh进行整合的一个例子,由于项目的jar包太大,我只上传了主要的jar文件
基于JBPM4.3 整合SSH2 框架的请假流程完整实例。 需要jar可以发email给我或留言
这个是jbpm+ssh实现的请假的例子,希望可以帮助大家!
jbpm4.4+ssh 整合 分享给大家供大家学习参考
jbpm4.4整合ssh代码,可在eclipse上运行。lib太多,请自行寻找
jBPM4.4整合SSH2
JBPM4.4整合SSH2的完整jar包,绝对可用!(注:此为Jar包第二部分,请搜索"JBPM4.4+SSH2完整整合jar包 par1",需要两部分一起解压!)