1、简述 Jbpm工作流框架与现有ssh框架的集成工作其实很简单,但国内外的资料太小,所以会在集成时走入太多误区,本文是在struts1.2,spring2.5,hibernate3.2上集成成功的详细步骤。其中解决了,jbpm的访问数据库session与原有hibernate的session不同的问题,string-max大字段问题。完成了流程部署web及后台程序。利用spring-modules-0.8当中的spring31做为集成的桥梁(其实它已经做好了集成,但文档和实例实在是太简单)。 使用jbpm-starters-kit-3.1.4生成数据库表及安装eclipse图形化配置
2、插件 1下载jbpm-starters-kit-3.1.4到其网站,包含所有需要的工具及jar包。 2数据库的安装以oracle为例,其它数据库可按此例修改。 2.1创建所需用户及表空间,如果有了用户和表空间就不需要了。 2.2 找到jbpm-starters-kit-3.1.4文件夹,在其下的jbpm文件夹的下级文件夹lib中加入oracle的驱动包ojdbc14.jar. 2.3 在jbpm\src\resources文件夹下建立oracle文件夹, 将\jbpm\src\resources\hsqldb里的create.db.hibernate.pro
3、perties和identity.db.xml文件copy到刚刚建立的oracle文件夹当中. 2.4 修改create.db.hibernate.properties文件,修改目标数据库的连接属性如下: # these properties are used by the build script to create # a hypersonic database in the build/db directory that contains # the jbpm tables and a process deployed in there
4、 hibernate.dialect=org.hibernate.dialect.OracleDialect hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver hibernate.connection.url=jdbc:oracle:thin:@10.62.1.12:1521:oracle hibernate.connection.username=dpf hibernate.connection.password=dpf hibernate.show_sql=true
5、
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
2.5 修改jbpm\src\config.files\hibernate.cfg.xml文件,同样是配置数据库的连接属性如下:
6、>
9、 properties="${basedir}/src/resources/oracle/create.db.hibernate.properties"/>
11、
12、gner\ jbpm-gpd-feature\eclipse下找到,需注意版本。 部署jbpm的jar包和moudle的jar包 1 把如下jar包放入\WEB-INF\lib文件夹下, spring-modules-jbpm31.jar可以在 spring-modules-0.8下找到,其它的都属于jbpm工具包。 bsh-1.3.0.jar bsf.jar spring-modules-jbpm31.jar jbpm-webapp-3.1.4.jar jbpm-identity-3.1.4.jar jbpm-3.1
13、4.jar
部署hbm文件到项目
1 在jbpm文件夹中找到所有的*.hbm.xml数据库映射文件。放到项目的一个文件夹当中。本例放到\com\gresoft\security\model\hbm文件夹中。并且在hibernate的sessionfactory建立时,设置为相关路径配置。
2 此文件需在spring管理的hibernate配置文件下修改,本例为
dataAccessContext-hibernate.xml,如下:
15、operty name="hibernateProperties">
18、 19、rty name="typeClass" value="org.jbpm.db.hibernate.StringMax" />
20、
1 此文件需在spring管理的hibernate配置文件下修改,本例为
dataAccessContext-hibernate.xml,如下:
21、
22、
2 增加类路径中jbpm.cfg.xml文件,可以根据
jbpm-starters-kit-3.1.4\jbpm\src\java.jbpm\org\jbpm\default.jbpm.cfg.xml
复制后修改。本例放到/datasql/jbpm.cfg.xml下。上面配置文件有相关配置。全部内容如下:
23、actory>
24、 29、gleton="true" />
31、xml中的修改
本例中描述如下:
32、ption; import java.io.Serializable; import java.security.Principal; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.S
33、ervletResponse; import javax.servlet.http.HttpServletRequest; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.springframework.web.context.WebApplicationContext; public class JbpmContextHolder implements Filter, Serializable { privat
34、e static final long serialVersionUID = 1L; String jbpmConfigurationResource = null; String jbpmContextName = null; boolean isAuthenticationEnabled = true; public void init(FilterConfig filterConfig) throws ServletException {
35、 // get the jbpm configuration resource this.jbpmConfigurationResource = filterConfig .getInitParameter("jbpm.configuration.resource"); // get the jbpm context to be used from the jbpm configuration
36、 this.jbpmContextName = filterConfig .getInitParameter("jbpm.context.name"); if (jbpmContextName == null) { jbpmContextName = JbpmContext.DEFAULT_JBPM_CONTEXT_NAME;
37、 } // see if authentication is turned off String isAuthenticationEnabledText = filterConfig .getInitParameter("authentication"); if ((isAuthenticationEnabledText != null)
38、 && ("disabled".equalsIgnoreCase(isAuthenticationEnabledText))) { isAuthenticationEnabled = false; } } public void doFilter(ServletRequest servletRequest, S
39、ervletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { String actorId = null; // see if we can get the authenticated swimlaneActorId if (servletRequest instan
40、ceof HttpServletRequest) { HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; Principal userPrincipal = httpServletRequest.getUserPrincipal(); if (userPrincipal != null) {
41、 actorId = userPrincipal.getName(); } } JbpmContext jbpmContext = getJbpmConfiguration(servletRequest) .createJbpmContext(jbpmContextName);
42、 try { if (isAuthenticationEnabled) { jbpmContext.setActorId(actorId); } filterChain.doFilter(servletRequest, servletResponse);
43、 } finally { jbpmContext.close(); } } /* * 从spring获取JbpmConfiguration的bean加载方式 */ protected JbpmConfiguration getJbpmConfiguration( Serv
44、letRequest servletRequest) { WebApplicationContext webApplicationContext = (WebApplicationContext) ((HttpServletRequest) servletRequest) .getSession() .getServletContext()
45、 .getAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); JbpmConfiguration jbpmConfiguration = (JbpmConfiguration) webApplicationContext
46、getBean("jbpmConfiguration"); // 得到业务Bean(在这里是你需要注入的bean) System.out.println("------------------------------------------------------------------------------------------"); System.out.println("jbpmconfiguration对象化=" + jbpmConfiguration.toString());
47、 System.out.println("------------------------------------------------------------------------------------------"); return jbpmConfiguration; } public void destroy() { } } 编写发布流
48、程定义xml的人机页面及程序 1 JSP页面使用struts1.2,spring2.0,hibernate3.2框架。此为流程发布页面。 <%@ page contentType="text/html;charset=UTF-8"%>
2 后台对应类 /******************************************************************************* * 文件名: JbpmAction.java





