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接口,存储流程实例和用户任务等动态数据
一个简单的请假流程演示:
其实开源社区有很多工做流的案例,但都不是本身想要的类型。因为工做须要,会逐步分享开发中所遇到的疑难问题和小细节,后面会开源一个简单的工做流完整实例,敬请关注。