flowable 的ProcessEngine配置

时间:2022-11-20 14:34:53

1 flowable process engine 是通过  flowable.cfg.xml 配置文件配置的。在spring 环境中是使用 flowable-context.xml 配置文件的,

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine() 方法会从 classpath 中寻找配置文件 flowable.cfg.xml 进行创建。

说明:flowable.cfg.xml 配置文件必须包含一个 ID 为processEngineConfiguration 的bean

flowable.cfg.xml 配置文件内容如下

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="processEngineConfiguration"
class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:mysql://196.131.9.62/flow1?allowMultiQueries=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="" /> <property name="databaseSchemaUpdate" value="true" /> <property name="asyncExecutorActivate" value="false" />
</bean> </beans>

2 将 flowable 与 springboot 集成

2.1 pom 文件如下

<?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.</modelVersion> <groupId>com.huitong</groupId>
<artifactId>flow1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging> <name>flow1 Maven Webapp</name>
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<flowable.version>6.3.</flowable.version>
</properties> <!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0..RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>${flowable.version}</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.</version>
<scope>provided</scope>
</dependency> </dependencies> <build>
<finalName>flow1</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

2.2 application.yml 配置

server:
port: spring:
application:
name: flow
datasource:
url: jdbc:mysql://127.0.0.1:3306/flow2?useUnicode=true&characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull
username: root
password: root123
hikari:
minimum-idle:
connection-timeout:
maximum-pool-size:
idle-timeout:
flowable:
#关闭定时任务JOB
async-executor-activate: false
database-schema-update: false
process:
#
definition-cache-limit:

2.3 获得常用的 service 类BaseService

@Service
public class BaseService { @Autowired
@Getter
private RepositoryService repositoryService; @Autowired
@Getter
private RuntimeService runtimeService; @Autowired
@Getter
private TaskService taskService; @Autowired
@Getter
private IdmIdentityService idmIdentityService; @Getter
@Autowired
private HistoryService historyService; @Autowired
@Getter
private ManagementService managementService; }