前言
JBPM是目前市場上主流開源工作引擎之一,在創建者Tom Baeyens離開JBoss后,JBPM的下一個版本jBPM5完全放棄了jBPM4的基礎代碼,基於Drools Flow重頭來過,目前官網已經推出了JBPM7的beta版本;Tom Baeyens加入Alfresco后很快推出了新的基於jBPM4的開源工作流系統Activiti。由此可以推測JBoss內部對jBPM未來版本的架構實現產生了嚴重的意見分歧。
環境
軟件版本SpringBoot1.5.10activiti-spring-boot-starter-basic6.0
搭建
花了半天的時間對比了下JBPM 和 Activit,以及兩個工作流的不同版本,最終選擇了 Activiti6 來實現,理由如下:
- JBPM 網上集成的資料甚少,且新版本相對比較笨重。
- Activiti 相對豐富的資料,並且高度與 SpringBoot 集成,之所以選擇 Activiti6 版本,是由於目前只有版本6的集成 starter。
創建 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 沒有相關 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=60
server.tomcat.max-threads=100
server.tomcat.uri-encoding=UTF-8
spring.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
每次應用啟動不檢查Activiti數據表是否存在及版本號是否匹配,提升應用啟動速度
spring.activiti.database-schema-update=false
保存歷史數據級別設置為full最高級別,便於歷史數據的追溯
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();
}
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(
PlatformTransactionManager transactionManager,
SpringAsyncExecutor springAsyncExecutor) throws IOException {
return baseSpringProcessEngineConfiguration(
activitiDataSource(),
transactionManager,
springAsyncExecutor);
}
}
啟動項目,會自動生成28張表:
- act_ge_ 通用數據表,ge是general的縮寫
- act_hi_ 歷史數據表,hi是history的縮寫,對應HistoryService接口
- act_id_ 身份數據表,id是identity的縮寫,對應IdentityService接口
- act_re_ 流程存儲表,re是repository的縮寫,對應RepositoryService接口,存儲流程部署和流程定義等靜態數據
- act_ru_ 運行時數據表,ru是runtime的縮寫,對應RuntimeService接口和TaskService接口,存儲流程實例和用戶任務等動態數據
演示
一個簡單的請假流程演示:



說明
其實開源社區有不少工作流的案例,但都不是自己想要的類型。由於工作需要,會逐步分享開發中所遇到的疑難問題和小細節,后面會開源一個簡單的工作流完整實例,敬請關注。

原文地址: https://zhuanlan.zhihu.com/p/60239970