创建空的maven项目,并加入springboot 2.2.0、flowable依赖,以下是完整maven配置(pom.xml)
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>flowable</artifactId>
<version>1.0-SNAPSHOT</version>
<name>flowable</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-boot.version>2.2.0.RELEASE</spring-boot.version>
<flowable.version>6.5.0</flowable.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-process</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.21</version>
</dependency>
<!-- 输出原始sql日志 -->
<dependency>
<groupId>com.googlecode.cxs.log4jdbc</groupId>
<artifactId>cxs-log4jdbc</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
</project>
配置ProcessEngine
package com.satuo20.flowable.config;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
* @author xiaodx
*/
@Configuration
public class ProcessEngineConfig {
/**
* ProcessEngine 配置,其中DataSourceTransactionManager和DataSource自动注入
* @param dataSourceTransactionManager
* @param dataSource
* @return
*/
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(DataSourceTransactionManager dataSourceTransactionManager,DataSource dataSource) {
SpringProcessEngineConfiguration springProcessEngineConfiguration = new SpringProcessEngineConfiguration();
springProcessEngineConfiguration.setDataSource(dataSource);
springProcessEngineConfiguration.setTransactionManager(dataSourceTransactionManager);
//不添加此项配置,在没创建表时,会抛出FlowableWrongDbException异常
springProcessEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
return springProcessEngineConfiguration;
}
}
数据源及flowable 相关配置application.yml
server:
port: 8080
flowable:
#关闭定时任务JOB
async-executor-activate: false
# 将databaseSchemaUpdate设置为true。当Flowable发现库与数据库表结构不一致时,会自动将数据库表结构升级至新版本。
database-schema-update: true
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
datasource:
driver-class-name: net.sf.log4jdbc.DriverSpy
# driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
# 如果不加这个参数,建表会失败:nullCatalogMeansCurrent=true
url: jdbc:log4jdbc:mysql://10.0.10.225:3306/flowable_xiaodx?characterEncoding=UTF-8&rewriteBatchedStatements=true&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
# url: jdbc:mysql://10.0.10.225:3306/flowable_xiaodx?characterEncoding=UTF-8&rewriteBatchedStatements=true&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
username: developer
password: 123456
druid:
initial-size: 5
max-active: 20
max-pool-prepared-statement-per-connection-size: 20
max-wait: 60000
min-evictable-idle-time-millis: 300000
min-idle: 5
pool-prepared-statements: true
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
validation-query: SELECT 1 FROM DUAL
max-idle: 4
启动类
package com.satuo20.flowable.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
/**
* @author xiaodx
*/
@SpringBootApplication
@ComponentScan("com.satuo20")
public class FlowableApp {
public static void main(String[] args) {
SpringApplication.run(FlowableApp.class,args);
}
}
整合完成及总结
- 使用springboot整合flowable非常简单
- 在配置数据库时,如果抛出FlowableWrongDbException异常,请在spring.datasource.url中拼接参数nullCatalogMeansCurrent=true
注意:本文归作者所有,未经作者允许,不得转载