工作流是OA系统不可或缺的一部分,今天介绍一下flowable工作流引擎。flowable 是一个业务流程管理(BPM),其核心是快速、稳定的BPMN2流程引擎内核,十分易于与 Spring集成使用。
1、 新建项目sc-flowable,添加Flowable依赖,对应的pom.xml文件如下
4.0.0
<groupId>com.flowable</groupId>
<artifactId>sc-flowable</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sc-flowable</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- HikariCP 连接池依赖 -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-basic</artifactId>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
2、新建配置文件:可以通过在application.yml或application.properties文件中添加以下配置来配置Flowable:
spring: datasource: driver-class-name : com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/flowable?characterEncoding=UTF-8 username: root password: root logging: level: ROOT: info flowable: #关闭定时任务JOB async-executor-activate: false #将databaseSchemaUpdate设置为true。当Flowable发现库与数据库表结构不一致时,会自动将数据库表结构升级至新版本。 database-schema-update: true 配置文件中主要配置数据库的地址、用户名及密码。
3、创建流程:使用Flowable Modeler创建流程定义,并将其部署到Spring Boot应用程序中;
4、新建springboot启动类:使用Flowable API在Spring Boot应用程序中启动流程实例;
package com.flowable;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication public class FlowableApplication {
public static void main(String[] args) {
SpringApplication.run(FlowableApplication.class, args);
}
5、验证是否集成flowable成功。运行后FlowableApplication.java,期间没有任何异常信息;查看数据库,已经自动生成了flowable相关的表结构。
对于Spring Boot中集成Flowable,以下是Flowable的一些优点:
1、可扩展性: Flowable提供了一组可扩展的API,使得开发人员可以根据需要自定义工作流。
2、可视化: Flowable Modeler使得创建和修改工作流变得容易,并且可以直接在应用程序中使用。
3、可追溯性: 运用Flowable,开发人员可以跟踪工作流程的进度,并监控工作流程中发生的事件。
4、可配置性: Flowable提供了一组配置选项,使得开发人员可以根据需要调整工作流。