【整合篇】JBPM4.4與Spring整合
我們大家都知道容器的好處,那麼工作流也提供了與spring整合的方式,將工作流引擎由spring容器統一管理起來,共同擁有容器的特性。下面來從程式碼的角度來看看整合與不整合的對比:
未整合:
引入相應的jar包,使用hibernate來持久化
配置檔案:
jbpm.cfg.xml:
jbpm.hibernate.cfg.xml:<?xml version="1.0" encoding="UTF-8"?> <jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <import resource="jbpm.tx.hibernate.cfg.xml" /> <import resource="jbpm.jpdl.cfg.xml" /> <import resource="jbpm.bpmn.cfg.xml" /> <import resource="jbpm.identity.cfg.xml" /> <!-- Job executor is excluded for running the example test cases. --> <!-- To enable timers and messages in production use, this should be included. --> <!-- <import resource="jbpm.jobexecutor.cfg.xml" /> --> </jbpm-configuration>
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1/jbpm</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">hejingyuan</property> <!-- <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property> <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property> <property name="hibernate.connection.username">sa</property> <property name="hibernate.connection.password"></property> --> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.format_sql">true</property> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /> </session-factory> </hibernate-configuration>
申請時應用:
ProcessEngine pe = Configuration.getProcessEngine(); TaskService ts = pe.getTaskService(); String taskId = request.getParameter("taskId"); String owner = request.getParameter("owner"); int day = Integer.parseInt(request.getParameter("day")); String reason = request.getParameter("reason"); Map map = new HashMap(); map.put("day", day); map.put("reason", reason); map.put("msg", "<hr>申請人:"+owner+"<br>請假天數:"+day+"<br>請假原因:"+reason); ts.setVariables(taskId,map); ts.completeTask(taskId); response.sendRedirect("index.jsp");
對應的原始碼:
/** singletone instance */
private static ProcessEngine singleton;
/** get the singleton ProcessEngine that is created from the default
* configuration file 'jbpm.cfg.xml'. */
public static ProcessEngine getProcessEngine() {
if (singleton == null) {
synchronized (Configuration.class) {
if (singleton == null) {
singleton = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();
}
}
}
return Configuration.singleton;
}
在jbpm的jar包下,我們可以看到:
這些是jbpm.cfg.xml檔案中引入的檔案
如何識別的hibernate的配置檔案:
整合後:
使用ssh架構:
web.xml檔案:
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SSH</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 配置Spring的OpenSessionInViewFilter,以解決懶載入異常的問題 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- hejingyuan新增 -->
<filter>
<filter-name>SSH</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SSH</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- 結束 -->
<!-- open session in view 的配置-->
<!-- <filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> -->
</web-app>
struts.xml配置檔案:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 問題一: namespace="/" 錯誤,找不到返回值 -->
<!-- 配置為開發模式 -->
<constant name="struts.devMode" value="true" />
<include file="struts-default.xml" />
<package name="hjy" extends="struts-default" namespace="/">
<!-- 審批流轉:審批流程管理 -->
<action name="processDefinitionAction_*" class="com.hjy.ssh.action.ProcessDefinitionAction" method="{1}">
<result name="list">/WEB-INF/jsp/definitionFlow/list.jsp</result>
<result name="addUI">/WEB-INF/jsp/definitionFlow/addUI.jsp</result>
<result name="toList" type="redirectAction">processDefinitionAction_list</result>
<!-- 下載專用的結果配置 -->
<result name="downloadProcessImage" type="stream">
<param name="contentType">image/png</param>
<param name="inputName">inputStream</param>
</result>
</action>
<!-- 審批流轉:申請流轉 -->
<action name="flowAction_*" class="com.hjy.ssh.action.FlowAction" method="{1}">
<result name="submitUI">/WEB-INF/jsp/flowAction/submitUI.jsp</result>
<result name="myApplicationList">/WEB-INF/jsp/flowAction/myApplicationList.jsp</result>
<result name="toMyApplicationList" type="redirectAction">flowAction_myApplicationList</result>
<result name="myTaskList">/WEB-INF/jsp/flowAction/myTaskList.jsp</result>
<result name="approveUI">/WEB-INF/jsp/flowAction/approveUI.jsp</result>
<result name="approveHistory">/WEB-INF/jsp/flowAction/approveHistory.jsp</result>
<result name="toMyTaskList" type="redirectAction">flowAction_myTaskList</result>
<result name="showProcessImageUI"> /WEB-INF/jsp/flowAction/showProcessImageUI.jsp</result>
</action>
<!-- 使用者管理 -->
<action name="userAction_*" class="com.hjy.ssh.action.UserAction" method="{1}">
<result name="toIndex" type="redirect">/index.jsp</result>
<result name="loginUI">/WEB-INF/jsp/user/loginUI.jsp</result>
</action>
<!-- 首頁 -->
<action name="homeAction_*" class="com.hjy.ssh.action.HomeAction" method="{1}">
<result name="{1}">/WEB-INF/jsp/homeAction/{1}.jsp</result>
</action>
</package>
</struts>
sring的配置檔案:applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 自動掃描與裝配bean -->
<context:component-scan base-package="com.hjy.ssh"></context:component-scan>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://127.0.0.1/ssh"></property>
<property name="username" value="root"></property>
<property name="password" value="hejingyuan"></property>
</bean>
<!--定義Hibernate的SessionFactory -->
<!-- SessionFactory使用的資料來源為上面的資料來源 -->
<!-- 指定了Hibernate的對映檔案和配置資訊 -->
<!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
<!-- 配置宣告式的事務管理(採用基於註解的方式) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- more bean definitions go here -->
<!-- 配置ProcessEngine -->
<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
<property name="jbpmCfg" value="jbpm.cfg.xml"></property>
</bean>
<bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
</beans>
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<!-- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1/ssh</property>
<property name="connection.username">root</property>
<property name="connection.password">hejingyuan</property> -->
<!-- JDBC connection pool (use the built-in) -->
<!-- <property name="connection.pool_size">1</property> -->
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<!-- <property name="current_session_context_class">thread</property> -->
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/hjy/ssh/beans/User.hbm.xml"/>
<mapping resource="com/hjy/ssh/beans/Application.hbm.xml"/>
<mapping resource="com/hjy/ssh/beans/ApproveInfo.hbm.xml"/>
<!-- 匯入JBPM4.4的對映檔案 -->
<mapping resource="jbpm.repository.hbm.xml" />
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
<mapping resource="jbpm.identity.hbm.xml" />
</session-factory>
</hibernate-configuration>
jbpm.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.default.cfg.xml" />
<import resource="jbpm.businesscalendar.cfg.xml" />
<!--
<import resource="jbpm.tx.hibernate.cfg.xml" />
-->
<!-- 與Spring整合需要匯入jbpm.tx.spring.cfg.xml檔案 -->
<import resource="jbpm.tx.spring.cfg.xml" />
<import resource="jbpm.jpdl.cfg.xml" />
<import resource="jbpm.bpmn.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
</jbpm-configuration>
部署應用:
@Resource
protected ProcessDefinitionService processDefinitionService;
/** 部署 ,即新增一個流程定義(上傳png和xml檔案)*/
public String add() throws Exception {
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(upload));
try {
processDefinitionService.deploy(zipInputStream);
} finally {
zipInputStream.close();
}
return "toList";
}
實現類:
@Override
public void deploy(ZipInputStream zipInputStream) {
// 部署流程
processEngine.getRepositoryService()//
.createDeployment()//
.addResourcesFromZipInputStream(zipInputStream)//
.deploy();
}
總結:
以上通過程式碼的方式展示,主要是讓大家更加系統性的來了解工作流的工作原理,而看配置檔案也是最簡單的一種方式。對於是否與spring或者其他框架整合,相信大家通過做日常專案也能體會到應用框架的優勢,以上的對比只是讓大家有個直觀的認識。
相關推薦
【整合篇】JBPM4.4與Spring整合
我們大家都知道容器的好處,那麼工作流也提供了與spring整合的方式,將工作流引擎由spring容器統一管理起來,共同擁有容器的特性。下面來從程式碼的角度來看看整合與不整合的對比: 未整合: 引入相應的jar包,使用hibernate來持久化 配
【整合篇】JBPM4.4業務與流程的整合
在這次學習工作流的過程中,工作流如何與業務結合有多種方式,雖然很簡單,但是每次都要再次梳理幾分鐘,這次拿出來整理一下,將它真正成為自己的知識。 從啟動流程開始說: 申請頁面:選擇所用流程(即畫的流程圖的id) <table cellpadding="0" ce
【升級篇】JBPM4.4過渡到Activiti
簡單介紹一下Activiti背景 Activiti的出現: Activiti的創始人Tom Baeyens是JBPM的創始人,由於與合作伙伴在JBPM的未來架構上產生意見分歧,Tom Baeyens在2010年離開了JBoss並加入Alfresco公司。Tom B
Python學習之路【第一篇】:Python簡介與入門
Python簡介 一、什麼是Python Python 是一個高層次的結合瞭解釋性、編譯性、互動性和麵向物件的指令碼語言。 Python 的設計具有很強的可讀性,相比其他語言經常使用英文關鍵字,其他語言的一些標點符號,它具有比其他語言更有特色語法結構。 Python 是一種解釋型語言:原始碼不是
從零構建AR APP新手教程【Android篇】(4)-APP互動邏輯及嵌入呼叫Unity
學習AR應用開發有一段時間了,自己開發了一款簡單的APP來練手,在這裡分享給大家。 前面介紹了Unity3D部分的實現,現在就來介紹Android原生部分的編碼實現。 1.APP基礎UI框架及互動邏輯 首頁就是簡單的ViewPager+Fragment,其中資料用
【中介軟體】MQ Rabbitmq 和spring整合
例一、Xml配置檔案 定義連線、定義了佇列或交換機、可以設定Key、定義了消費者及路徑 <beans xmlns="http://www.springframework.org/schema/
Mybatis(3、延遲載入、查詢快取、與ehcache整合、逆向工程、與spring整合)
版權宣告:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/www1056481167/article/details/70597788 延遲載入 延遲載入:先從單表查詢、需要時再從關聯表去關聯查詢,大大提高 資料庫效能,因為
基於哨兵【sentinel】模式的redis服務叢集並與spring整合
最近接手了一個PHP老專案,裡面用到了redis快取,基於sentinel模式的叢集。專案裡面redis的連線讀寫都是用PHP實現的,並把不同的資訊儲存於不同的dbindex下,即分db儲存內容。看了下,由於本人是搞Java的,決定用Java進行重構。於是就進
【springboot spring mybatis】看我怎麼將springboot與spring整合mybatis與druid資料來源
# 概述 本文分別講述了`spring`與`springboot`是怎麼整合`mybatis`與`druid`資料來源的?如果你只是想實現其中一種,那你就不要把他們的配置過程搞混了。 ## 1、mybatis `MyBatis` 本是apache的一個開源專案iBatis, 2010年這個專案由apache
3、非線性結構--樹與二叉樹——數據結構【基礎篇】
位置 enter 深度 基礎 表達式 左右 -a 基礎篇 先序遍歷 非線性結構--樹與二叉樹 二叉樹的基礎知識: 二叉樹的特點: 1、每個結點的度<=2 2、二叉樹是有序樹 二叉樹的五種不
【Spark篇】---Spark中資源調度源碼分析與應用
部分 app post 類名 inf master 執行過程 efault spark 一、前述 Spark中資源調度是一個非常核心的模塊,尤其對於我們提交參數來說,需要具體到某些配置,所以提交配置的參數於源碼一一對應,掌握此節對於Spark在任務執行過程中的資源分配會更上
MySQL數據庫學習【第九篇】索引原理與慢查詢優化
xxx 結構 復合 unix select查詢 全文搜索 等等 學習 獲取數據 一、介紹 1.什麽是索引? 一般的應用系統,讀寫比例在10:1左右,而且插入操作和一般的更新操作很少出現性能問題,在生產環境中,我們遇到最多的,也是最容易出問題的,還是一些復雜的查詢操作,因此對
Python之路【第十九篇】:sys與os模塊
改變 python 隱藏 post 系統 rmdir 最大的 mman 就是 與解釋器相關的一些操作在sys模塊中,與系統相關的一些操作在os模塊中 sys模塊 sys.argv 命令行參數List,第一個元素是程序本身路徑 sys.exit(n)
【PHP篇】變數與常量
變數: 變數的作用域為函式區域 判斷是否存在:isset($變數名);//返回bool 判斷是否為空:empty($變數名)//變數未宣告或者值為空返回1,否則返回false 清除變數:unset($變數名) 或者 $變數名=null; 引用:$a=10; $b
一種古老的技術:axis1.4操作WebService,實現與Spring整合
這是pom檔案中需要的axis需要的依賴 <dependency> <groupId>org.springframework</groupId> <artifactId>spr
【JavaBug篇】java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFact
Got unchecked and undeclared exception which called by 192.168.228.1. service: cn.uppp.user.IUserCor
【第七篇】Qt學習與使用---TreeView目錄以及其點選事件
1、目的 想要寫一個目錄,可以列出某一路徑下所有的 檔案,並且可以點選開啟。(初始是想做一個閱讀器程式 ) 2、思路 (1)首先需要將檔名稱以目錄的 形式列出。 (2)可以開啟不同型別的檔案,如 資料夾,PDF,doc,csv,&nb
【第六篇】Qt學習與使用---在qt中列印PDF檔案(不是生成PDF)
1、目的 如題,列印pdf檔案中的內容。 2、思路 (1)思路1:可以通過Poppler類來讀取pdf中的內容,並轉化成圖片,再 列印這些圖片。這個方法的瑕疵是,需要在列印的時候準確的寫出一頁圖片在A4紙上的列印座標和大小。否則會導致與原文不同。 (2)思路2:呼叫系統介面,讓win
【第五篇】Qt學習與使用---自定義的圖片輪播類(滾動播放圖片)
1、目標 編寫一個類,可以展示幾張圖片。類似於現在流行的視訊播放器的首頁中出現的滾動展示的控制元件。 2、 具體要求 (1)一次性展示三張圖片,左中右。中間的圖片至於頂部,旁邊的圖片被覆蓋,只露出一部分。 (2) 切換圖片的時候,呈現動態效果,需要有一個移動的過程。
【資料庫篇】——4.使用者登入註冊系統設計和分析思路
1.功能需求分析 本系統的功能就兩個:使用者登入和註冊。a.使用者登入需要我們根據使用者的輸入的資訊到資料查詢使用者的賬號密碼是否能夠匹配的上。b.使用者註冊需要我們將使用者的資訊加入到資料庫中。2.架構設計:MVC的模式(模式一) 在這裡我們採用MVC的模式進行開發,這