SpringBoot开发案例之整合Activiti工作流引擎
前言
JBPM是目前市場(chǎng)上主流開源工作引擎之一,在創(chuàng)建者Tom Baeyens離開JBoss后,JBPM的下一個(gè)版本jBPM5完全放棄了jBPM4的基礎(chǔ)代碼,基于Drools Flow重頭來(lái)過(guò),目前官網(wǎng)已經(jīng)推出了JBPM7的beta版本;Tom Baeyens加入Alfresco后很快推出了新的基于jBPM4的開源工作流系統(tǒng)Activiti。由此可以推測(cè)JBoss內(nèi)部對(duì)jBPM未來(lái)版本的架構(gòu)實(shí)現(xiàn)產(chǎn)生了嚴(yán)重的意見分歧。
搭建
花了半天的時(shí)間對(duì)比了下JBPM 和 Activit,以及兩個(gè)工作流的不同版本,最終選擇了 Activiti6 來(lái)實(shí)現(xiàn),理由如下:
- JBPM 網(wǎng)上集成的資料甚少,且新版本相對(duì)比較笨重。
- Activiti 相對(duì)豐富的資料,并且高度與 SpringBoot 集成,之所以選擇 Activiti6 版本,是由于目前只有版本6的集成 starter。
創(chuàng)建 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.itstyle.bpm</groupId><artifactId>spring-boot-activiti</artifactId><packaging>jar</packaging><version>0.0.1-SNAPSHOT</version><name>spring-boot-activiti</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><!-- 截止2019年2月1日 spring-boot 2.0 沒(méi)有相關(guān) activiti 的 starter-basic--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.10.RELEASE</version><relativePath/></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-spring-boot-starter-basic</artifactId><version>6.0.0</version></dependency></dependencies><build><finalName>spring-boot-activiti</finalName></build> </project>配置 application.properties:
server.context-path=/ server.port=8080 server.session-timeout=60server.tomcat.max-threads=100 server.tomcat.uri-encoding=UTF-8spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/spring-boot-activiti?characterEncoding=utf-8&useSSL=false spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver # Specify the DBMS spring.jpa.database = MYSQL # Show or not log for each sql query spring.jpa.show-sql = true # DDL mode. This is actually a shortcut for the "hibernate.hbm2ddl.auto" property. Default to "create-drop" when using an embedded database, "none" otherwise. spring.jpa.hibernate.ddl-auto = update # Hibernate 4 naming strategy fully qualified name. Not supported with Hibernate 5. spring.jpa.hibernate.naming.strategy = org.hibernate.cfg.ImprovedNamingStrategy # stripped before adding them to the entity manager) spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect#每次應(yīng)用啟動(dòng)不檢查Activiti數(shù)據(jù)表是否存在及版本號(hào)是否匹配,提升應(yīng)用啟動(dòng)速度 spring.activiti.database-schema-update=false #保存歷史數(shù)據(jù)級(jí)別設(shè)置為full最高級(jí)別,便于歷史數(shù)據(jù)的追溯 spring.activiti.history-level=full聲名為配置類 ActivitiConfig:
@Configuration//聲名為配置類,繼承Activiti抽象配置類 public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {@Bean@Primary@ConfigurationProperties(prefix = "spring.datasource")public DataSource activitiDataSource() {return DataSourceBuilder.create().build();}@Beanpublic SpringProcessEngineConfiguration springProcessEngineConfiguration(PlatformTransactionManager transactionManager,SpringAsyncExecutor springAsyncExecutor) throws IOException {return baseSpringProcessEngineConfiguration(activitiDataSource(),transactionManager,springAsyncExecutor);} }啟動(dòng)項(xiàng)目,會(huì)自動(dòng)生成28張表:
act_ge_ 通用數(shù)據(jù)表,ge是general的縮寫
act_hi_ 歷史數(shù)據(jù)表,hi是history的縮寫,對(duì)應(yīng)HistoryService接口
act_id_ 身份數(shù)據(jù)表,id是identity的縮寫,對(duì)應(yīng)IdentityService接口
act_re_ 流程存儲(chǔ)表,re是repository的縮寫,對(duì)應(yīng)RepositoryService接口,存儲(chǔ)流程部署和流程定義等靜態(tài)數(shù)據(jù)
act_ru_ 運(yùn)行時(shí)數(shù)據(jù)表,ru是runtime的縮寫,對(duì)應(yīng)RuntimeService接口和TaskService接口,存儲(chǔ)流程實(shí)例和用戶任務(wù)等動(dòng)態(tài)數(shù)據(jù)
演示
一個(gè)簡(jiǎn)單的請(qǐng)假流程演示:
說(shuō)明
其實(shí)開源社區(qū)有不少工作流的案例,但都不是自己想要的類型。由于工作需要,會(huì)逐步分享開發(fā)中所遇到的疑難問(wèn)題和小細(xì)節(jié),后面會(huì)開源一個(gè)簡(jiǎn)單的工作流完整實(shí)例,敬請(qǐng)關(guān)注。
轉(zhuǎn)載于:https://www.cnblogs.com/smallSevens/p/10386042.html
總結(jié)
以上是生活随笔為你收集整理的SpringBoot开发案例之整合Activiti工作流引擎的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: NAT概念解释(不完全版,但不会搞错..
- 下一篇: JavaScript实现省市联动