Activiti 是最受欢迎、使用人数最多的工作流框架,所有涉及到流程审批的地方,都会使用到 Activiti。本文将基于 Spring Boot 2.3 简易集成 Activiti 6。
Activiti 官网: https://www.activiti.org
./activiti-workflow/pom.xml
<!-- Activiti -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>${activiti.version}</version>
</dependency>
其中 ${activiti.version}
的版本为 6.0.0
完整 pom 文件参考项目源码
./activiti-workflow/src/main/resources/application.yml
## spring config
spring:
activiti:
check-process-definitions: false
database-schema-update: true
process-definition-location-prefix: classpath:/
datasource:
url: "jdbc:mysql://127.0.0.1:3306/demo_activiti?useUnicode=true&characterEncoding=utf8\
&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8\
&useSSL=true&allowMultiQueries=true&autoReconnect=true&nullCatalogMeansCurrent=true"
username: root
password: "root"
hikari:
driver-class-name: com.mysql.cj.jdbc.Driver
属性说明:
database-schema-update
: 数据库表模式,可选项为: true
,项目初始化时检查 Activiti 数据库表,当 Activiti 数据库表不存在时,创建对应的表,如果已经存在,则不重复创建,默认为 true
;false
: 项目初始化时,默认 Activiti 数据库表已经创建,如果没有,则抛出异常;create-drop
:流程开始时创建数据库表,流程结束后删除数据库表
process-definition-location-prefix
: 流程文件(bpmn) 位置前缀,一般将流程文件存放在 resources/processes
目录下
./activiti-workflow/src/main/java/com/ljq/demo/springboot/activiti/ActivitiWorkflowApplication.java
package com.ljq.demo.springboot.activiti;
import org.activiti.spring.boot.SecurityAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @author junqiang.lu
*/
@EnableSwagger2
@MapperScan("com.ljq.demo.springboot.activiti.dao")
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class ActivitiWorkflowApplication {
public static void main(String[] args) {
SpringApplication.run(ActivitiWorkflowApplication.class, args);
}
}
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
这里需要排除 SecurityAutoConfiguration.class
,避免启动失败
至此,SpringBoot 已经成功集成 Activiti, 接下来就可以绘制流程图,启动工作流了。
Activiti6.0教程(3) - springboot项目中使用activiti6.0配置及启动
commit 0510343b79ee8f2931892d55b64b9af7fa1981a4
Author: ljq <[email protected]>
Date: Wed Jul 15 15:33:15 2020 +0800
代码-新增 SpringBoot2.x 集成 Activiti 工作流
版本回退命令:
git reset --soft 0510343b79ee8f2931892d55b64b9af7fa1981a4