SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)(一)

简介: SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(图解)

最终效果展示

SpringBoot 集成 Flowable Modeler 实现流程操作可视化工程

工程搭建步骤

下载 Flowable 源码

这里选择的版本为 6.4.1,这个版本使用比较多,没有什么问题,但是千万不要选择 6.4.2 版本,这个版本有发版问题。

下载地址:https://github.com/flowable/flowable-engine/releases/tag/flowable-6.4.1/

这里也附上中文版用户手册学习地址:Flowable BPMN 用户手册

Flowable 引擎基础配置

由于是 spring-boot 集成,因此直接选择 flowable-spring-boot-starter,里面提供了齐全的 REST API

新建springboot项目:

添加依赖

spring-boot 集成了 flowable包包,提供了 flowable-spring-boot-starter,里面提供了齐全的 REST API,所以我们直接选择

<!-- Flowable spring-boot 版套餐 -->
<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-spring-boot-starter</artifactId>
    <version>6.4.1</version>
</dependency>

添加yml配置:

# flowable 配置
flowable:
  # 关闭异步,不关闭历史数据的插入就是异步的,会在同一个事物里面,无法回滚
  # 开发可开启会提高些效率,上线需要关闭
  async-executor-activate: false

注意:Flowable 使用 SLF4J 作为内部日志框架。所以我们使用 log4j 作为 SLF4J 的实现

添加log4j 依赖

<!-- Flowable 内部日志采用 SLF4J -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.21</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.21</version>
</dependency>

resource 目录下新建文件 log4j.properties

log4j.rootLogger=DEBUG, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n

新建flowable的配置文件 flowable.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<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://127.0.0.1:3306/flowable"/>
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
        <property name="jdbcUsername" value="root"/>
        <property name="jdbcPassword" value="root"/>
        <property name="databaseSchemaUpdate" value="true"/>
    </bean>
</beans>

添加加载配置文件的依赖:

<!-- 配置文件处理器 -->
<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-configuration-processor</artifactId>
 </dependency>

编写流程引擎配置文件,初始化流程引擎

代码如下:

package com.flowable.modeler.config;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.logging.Logger;
@Configuration
public class ProcessEngineConfig {
    private Logger logger = (Logger) LoggerFactory.getLogger(ProcessEngineConfig.class);
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.driver-class-name}")
    private String driverClassName;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;
    /**
     * 初始化引擎流程
     * @return
     */
    public ProcessEngine initProcessEngine() {
        logger.info("=============================ProcessEngineBegin=============================");
        // 流程引擎配置
        ProcessEngineConfiguration cfg = null;
        try {
            cfg = new StandaloneInMemProcessEngineConfiguration()
                    .setJdbcUrl(url)
                    .setJdbcUsername(username)
                    .setJdbcPassword(password)
                    .setJdbcDriver(driverClassName)
                    // 初始化基础表,不需要的可以改为 DB_SCHEMA_UPDATE_FALSE
                    .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
                    // 默认邮箱配置
                    // 发邮件的主机地址,先用 QQ 邮箱
                    .setMailServerHost("smtp.qq.com")
                    // POP3/SMTP服务的授权码
                    .setMailServerPassword("xxxxxxx")
                    // 默认发件人
                    .setMailServerDefaultFrom("1795018360@qq.com")
                    // 设置发件人用户名
                    .setMailServerUsername("管理员")
                    // 解决流程图乱码
                    .setActivityFontName("宋体")
                    .setLabelFontName("宋体")
                    .setAnnotationFontName("宋体");
            ;
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 初始化流程引擎对象
        ProcessEngine processEngine =cfg.buildProcessEngine();
        logger.info("=============================ProcessEngineEnd=============================");
        return processEngine;
    }
}

PS:这里不用再单独对流程引擎中的 8 个核心服务做初始化,因为我们使用 flowable-spring-boot-starter 依赖,会自动帮忙注册好,不需要自己再注册,直接使用即可

集成 Modeler 前端

打开下载的flowable源码文件夹 flowable-ui-modeler

路径:flowable-engine-flowable-6.4.1\modules\flowable-ui-modeler

  • flowable-ui-modeler-app:主要为前端界面,文件在 resource/static 下
  • flowable-ui-modeler-conf:主要为一些配置文件 Configuration
  • flowable-ui-modeler-logic:主要为一些业务逻辑还有 SQL
  • flowable-ui-modeler-rest:主要为 rest 接口

添加依赖:

<!-- flowable 集成依赖 rest,logic,conf -->
<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-ui-modeler-rest</artifactId>
    <version>6.4.1</version>
</dependency>
<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-ui-modeler-logic</artifactId>
    <version>6.4.1</version>
</dependency>
<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-ui-modeler-conf</artifactId>
    <version>6.4.1</version>
</dependency>

在项目中的 resource 文件夹下新建一个 static 文件夹

SpringBoot 能自动读取 static 目录下的静态文件,因此文件夹名称不可随意更改

复制 flowable-ui-modeler-app 包中 resources\static 下所有前端代码文件,复制到我们自己的项目static 文件夹下

自定义配置类

然后我们想要把他连接到Flowable包的代码逻辑和存储数据库就要编写与应用我们的项目自己配置类

其中主要改用Flowable包下的几个配置类


相关文章
|
5天前
|
Java 关系型数据库 MySQL
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口(下)
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口
19 0
|
5天前
|
Java 关系型数据库 MySQL
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口(上)
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口
23 0
|
3天前
|
Java 数据库连接 数据安全/隐私保护
springBoot集成token认证,最全Java面试知识点梳理
springBoot集成token认证,最全Java面试知识点梳理
|
5天前
|
前端开发 关系型数据库 MySQL
【MySQL × SpringBoot 突发奇想】全面实现流程 · 数据库导出Excel表格文件的接口
【MySQL × SpringBoot 突发奇想】全面实现流程 · 数据库导出Excel表格文件的接口
27 0
|
5天前
|
NoSQL Java MongoDB
【MongoDB 专栏】MongoDB 与 Spring Boot 的集成实践
【5月更文挑战第11天】本文介绍了如何将非关系型数据库MongoDB与Spring Boot框架集成,以实现高效灵活的数据管理。Spring Boot简化了Spring应用的构建和部署,MongoDB则以其对灵活数据结构的处理能力受到青睐。集成步骤包括:添加MongoDB依赖、配置连接信息、创建数据访问对象(DAO)以及进行数据操作。通过这种方式,开发者可以充分利用两者优势,应对各种数据需求。在实际应用中,结合微服务架构等技术,可以构建高性能、可扩展的系统。掌握MongoDB与Spring Boot集成对于提升开发效率和项目质量至关重要,未来有望在更多领域得到广泛应用。
【MongoDB 专栏】MongoDB 与 Spring Boot 的集成实践
|
5天前
|
消息中间件 JSON Java
RabbitMQ的springboot项目集成使用-01
RabbitMQ的springboot项目集成使用-01
|
5天前
|
搜索推荐 Java 数据库
springboot集成ElasticSearch的具体操作(系统全文检索)
springboot集成ElasticSearch的具体操作(系统全文检索)
|
5天前
|
前端开发
基于RuoYi-Flowable-Plus的若依ruoyi-nbcio支持自定义业务表单流程的集成方法与步骤(二)
基于RuoYi-Flowable-Plus的若依ruoyi-nbcio支持自定义业务表单流程的集成方法与步骤(二)
10 0
|
5天前
|
SQL 前端开发 数据库
基于RuoYi-Flowable-Plus的若依ruoyi-nbcio支持自定义业务表单流程的集成方法与步骤(一)
基于RuoYi-Flowable-Plus的若依ruoyi-nbcio支持自定义业务表单流程的集成方法与步骤(一)
20 2
基于RuoYi-Flowable-Plus的若依ruoyi-nbcio支持自定义业务表单流程的集成方法与步骤(一)
|
5天前
|
消息中间件 Java Spring
Springboot 集成Rabbitmq之延时队列
Springboot 集成Rabbitmq之延时队列
7 0