前言
JBPM是目前市场上主流开源工作引擎之一,在创建者Tom Baeyens离开JBoss后,JBPM的下一个版本jBPM5完全放弃了jBPM4的基础代码,基于Drools Flow重头来过,目前官网已经推出了JBPM7的beta版本;Tom Baeyens加入Alfresco后很快推出了新的基于jBPM4的开源工作流系统Activiti。由此可以推测JBoss内部对jBPM未来版本的架构实现产生了严重的意见分歧。
环境软件版本SpringBoot1.5.10
activiti-spring-boot-starter-basic6.0
搭建
花了半天的时间对比了下JBPM 和 Activit,以及两个工作流的不同版本,最终选择了 Activiti6 来实现,理由如下:JBPM 网上集成的资料甚少,且新版本相对比较笨重。
Activiti 相对丰富的资料,并且高度与 SpringBoot 集成,之所以选择 Activiti6 版本,是由于目前只有版本6的集成 starter。
创建 pom.xml:
xsi:schemaLocation="/POM/4.0.0 /maven-v4_0_0.xsd">
4.0.0
com.itstyle.bpm
spring-boot-activiti
jar
0.0.1-SNAPSHOT
spring-boot-activiti
UTF-8
org.springframework.boot
spring-boot-starter-parent
1.5.10.RELEASE
org.springframework.boot
spring-boot-starter-web
org.activiti
activiti-spring-boot-starter-basic
6.0.0
spring-boot-activiti
配置 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接口,存储流程实例和用户任务等动态数据
演示
一个简单的请假流程演示:
说明
其实开源社区有不少工作流的案例,但都不是自己想要的类型。由于工作需要,会逐步分享开发中所遇到的疑难问题和小细节,后面会开源一个简单的工作流完整实例,敬请关注。