来到这的人想必已经知道flowable的作用以及用途,下面就直接解释如何在springboot中引入flowable并进行一系列的操作。
1、首先引入依赖(根据你的boot版本3选择7,boot2选择6)我这里是boot3
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>7.0.1</version>
</dependency>
2、修改配置文件yml,添加内容
flowable:
# 关闭定时任务JOB
async-executor-activate: false
# 在引擎启动时,如果数据库架构与 Flowable 引擎期望的架构不一致,Flowable 会自动更新数据库架构。这包括创建缺失的表和列,以及修改现有的表和列以匹配最新版本
database-schema-update: true
若是你的数据库是MySQL8(我建议你加上就完事了),则在url上添加&nullCatalogMeansCurrent=true,具体样子如下所示:
url: jdbc:mysql://localhost:3306/stcj?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
3、配置线程池,创建一个类
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 线程池
*/
@Configuration
public class ThreadPoolConfig {
@Bean(name = "customThreadPool")
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5); // 核心线程数
executor.setMaxPoolSize(10); // 最大线程数
executor.setQueueCapacity(25); // 队列容量
executor.setThreadNamePrefix("CustomThread-"); // 线程名称前缀
executor.initialize(); // 初始化线程池
return executor;
}
@Bean(name = {"threadPoolTaskExecutor", "applicationTaskExecutor"})
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5); // 核心线程数
executor.setMaxPoolSize(10); // 最大线程数
executor.setQueueCapacity(25); // 队列容量
executor.setThreadNamePrefix("ThreadPool-"); // 线程名称前缀
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
return executor;
}
}
启动之后我们就会发现数据库中多了60多张表,flowable就是使用这些表完成业务操作的。这样我们项目中就已经初步引入flowable。
第二篇文章介绍这些表具体有什么作用,核心表是那些。可以关注一下本系列,持续追踪一下。