JBPM是目前市場上主流開源工做引擎之一,在建立者Tom Baeyens離開JBoss後,JBPM的下一個版本jBPM5徹底放棄了jBPM4的基礎代碼,基於Drools Flow重頭來過,目前官網已經推出了JBPM7的beta版本;Tom Baeyens加入Alfresco後很快推出了新的基於jBPM4的開源工做流系統Activiti。由此能夠推測JBoss內部對jBPM將來版本的架構實現產生了嚴重的意見分歧。java
花了半天的時間對比了下JBPM 和 Activit,以及兩個工做流的不一樣版本,最終選擇了 Activiti6 來實現,理由以下:mysql
建立 pom.xml:web
<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:spring
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:sql
@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張表:apache
act_ge_ 通用數據表,ge是general的縮寫tomcat
act_hi_ 歷史數據表,hi是history的縮寫,對應HistoryService接口session
act_id_ 身份數據表,id是identity的縮寫,對應IdentityService接口架構
act_re_ 流程存儲表,re是repository的縮寫,對應RepositoryService接口,存儲流程部署和流程定義等靜態數據app
act_ru_ 運行時數據表,ru是runtime的縮寫,對應RuntimeService接口和TaskService接口,存儲流程實例和用戶任務等動態數據
一個簡單的請假流程演示:
其實開源社區有很多工做流的案例,但都不是本身想要的類型。因爲工做須要,會逐步分享開發中所遇到的疑難問題和小細節,後面會開源一個簡單的工做流完整實例,敬請關注。