SpringBoot整合Flowable
1. 引入依赖
flowable-spring-boot-starter-basic
<dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-basic</artifactId> <version>${flowable.version}</version></dependency>
完整pom
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.16.RELEASE</version> <relativePath/> <!-- lookup parent from repository --></parent><properties> <java.version>1.8</java.version> <flowable.version>6.4.2</flowable.version> <slf4j.version>1.7.25</slf4j.version></properties><dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.4</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-basic</artifactId> <version>${flowable.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency></dependencies>
2. 配置文件
application.properties
主要配置数据源
server.port=10000server.servlet.context-path=/spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.url=jdbc:mysql://127.0.0.1:3306/flowable-springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=falsespring.datasource.username=rootspring.datasource.password=123456# druid configspring.datasource.druid.initial-size=5spring.datasource.druid.min-idle=5spring.datasource.druid.max-active=20spring.datasource.druid.max-wait=60000spring.datasource.druid.time-between-eviction-runs-millis=60000spring.datasource.druid.min-evictable-idle-time-millis=300000spring.datasource.druid.validation-query=SELECT 1 FROM DUALspring.datasource.druid.test-while-idle=truespring.datasource.druid.test-on-return=falsespring.datasource.druid.test-on-borrow=falsespring.datasource.druid.pool-prepared-statements=truespring.datasource.druid.max-pool-prepared-statement-per-connection-size=20spring.datasource.druid.filters=stat,wall,log4jspring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
3. 启动查看数据库
启动时,默认会获取 classpath*:/processes/
下的所有.bpmn20.xml
, .bpmn
文件,并完成部署。
查看数据库,表已经自动创建。
4. 设置流程文件位置
设置流程文件位置并在启动时完成部署;
查看 org.flowable.spring.boot.FlowableProperties
完成配置
# 是否开启自动部署流程定义 默认trueflowable.check-process-definitions=true# 流程定义文件位置flowable.process-definition-location-prefix=classpath*:/bpmn/# 流程文件后缀flowable.process-definition-location-suffixes[0]=**.bpmn20.xmlflowable.process-definition-location-suffixes[1]=**.bpmn
5. 自定义ID生成器
public class CustomIdGenerator implements IdGenerator { @Override public String getNextId() { String uuid = UUID.randomUUID().toString(); String nextId = "custom:" uuid.replaceAll("-", ""); return nextId; }}
@Beanpublic IdGenerator idGenerator() { return new CustomIdGenerator();}
6. Flowable配置类
org.flowable.spring.boot.FlowableProperties
org.flowable.spring.boot.process.FlowableProcessProperties
org.flowable.spring.boot.app.FlowableAppProperties
org.flowable.spring.boot.idm.FlowableIdmProperties
org.flowable.spring.boot.FlowableMailProperties
org.flowable.spring.boot.FlowableHttpProperties
赞 (0)