springboot 集成 flowable

随着企业对于业务流程管理需求的增加,流程引擎在企业信息化建设中的作用越来越重要。Flowable是一个开源的轻量级业务流程管理(BPM)和工作流引擎,它支持BPMN 2.0标准。
Flowable的一些特点:

  • 安装集成:Flowable可以与Spring Boot等现代开发框架集成,提供了一套完整的工具和API来支持工作流的建表、设计和实施。
  • 流程设计:使用Flowable,开发者可以构建符合BPMN 2.0规范的流程定义,这些流程定义可以通过流程设计器进行可视化设计,也可以通过XML或JSON格式的文件直接编辑。
  • 流程实例管理:Flowable允许用户创建和管理流程实例,查询实例状态,以及在运行时对流程实例进行干预,如启动、暂停或终止实例。
  • 数据访问:Flowable提供了访问流程相关数据的API,允许应用程序在流程执行过程中存取相关数据。
  • 数据库支持:Flowable支持多种数据库,这使得它可以在不同的企业环境中灵活部署和使用。
  • 社区文档:作为一个开源项目,Flowable拥有一个活跃的社区,提供丰富的文档和案例,帮助开发者学习和解决问题。
    今天介绍的是springboot2.3版本集成flowable。

集成flowable

pom.xml中引入以下内容:

  <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>${flowable.version}</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-ui-modeler</artifactId>
            <version>${flowable.version}</version>
        </dependency>

        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-ui-admin</artifactId>
            <version>${flowable.version}</version>
        </dependency>

        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-ui-idm</artifactId>
            <version>${flowable.version}</version>
        </dependency>

        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-ui-task</artifactId>
            <version>${flowable.version}</version>
        </dependency>

配置文件追加配置自动建表:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/tt?useSSL=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
    username: root
    password: pass
    driverClassName: com.mysql.cj.jdbc.Driver
flowable:
  async-executor-activate: false
  database-schema-update: true

默认会启动liquibase, 可关闭:

spring:
  liquibase:
    enabled: false

生成的表如下:
在这里插入图片描述

生成的表分别做什么用的

如果用过Activity的同学, 就会发现表名很多相同的, 但Flowable的表多了很多, 毕竟两者早期是同一个产品。表的功能一般可以通过第二个词语缩写来进行区分。
Flowable 生成的数据表主要用于支撑工作流引擎的运行和管理。这些表中包括但不限于以下几类:

  • ACT_RE_: 以 “RE” 为前缀的表属于仓库服务(RepositoryService),它们主要存储与流程定义相关的静态信息,如流程定义、流程的资源(图片、规则等)。
  • ACT_RU_: 以 “RU” 为前缀的表属于运行时服务(RuntimeService),存储着流程实例在执行期间的动态数据,包括流程变量、用户任务、变量、职责(job)等。
  • ACT_ID_: 以 “ID” 为前缀的表与组织机构或用户身份有关,涉及用户、组和权限等信息。
  • ACT_HI_: 是Flowable工作流引擎中使用的历史数据表。
  • ACT_GE_:主要用于存储全局通用的数据和设置,这些数据在各种情况下都可能被使用

简单使用flowable

用户admin密码test:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
简单绘制一个请假审批:

  • 部门经理线的流条件:${day>1 && day<=3}
  • 组长的流条件:${day<=1}
  • 总经理的流条件:${day>3}
    在这里插入图片描述
    下载该文件命名为a.bpmn20.xml:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.8.1">
  <process id="a" name="a" isExecutable="true">
    <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
    <userTask id="sid-1728059A-DB68-4E2F-A07F-4AE72EC7F5D7" name="组长" flowable:formFieldValidation="true"></userTask>
    <exclusiveGateway id="sid-431B47DD-3932-49D2-8B5A-51FBE9C8A50B"></exclusiveGateway>
    <sequenceFlow id="sid-EA5097EB-7C3A-4295-86F5-8EFFC6F3E02A" sourceRef="startEvent1" targetRef="sid-431B47DD-3932-49D2-8B5A-51FBE9C8A50B"></sequenceFlow>
    <userTask id="sid-96F84EB8-DB79-4092-89A5-141313627020" name="部门经理" flowable:formFieldValidation="true"></userTask>
    <userTask id="sid-09FB7A15-7582-4785-B635-05E745D56438" name="总经理" flowable:formFieldValidation="true"></userTask>
    <endEvent id="sid-CF77490C-2721-4269-9A2C-301CD4DD6F15"></endEvent>
    <sequenceFlow id="sid-38EF250C-CF01-414A-BDC3-A0E2CBAB9175" sourceRef="sid-1728059A-DB68-4E2F-A07F-4AE72EC7F5D7" targetRef="sid-CF77490C-2721-4269-9A2C-301CD4DD6F15"></sequenceFlow>
    <endEvent id="sid-F9DE2B7F-F2B4-4D7A-872C-D620EC006C80"></endEvent>
    <sequenceFlow id="sid-0537C179-756A-4F54-AF48-BCD3669EC88B" sourceRef="sid-96F84EB8-DB79-4092-89A5-141313627020" targetRef="sid-F9DE2B7F-F2B4-4D7A-872C-D620EC006C80"></sequenceFlow>
    <endEvent id="sid-6224E896-E5DF-4AD8-9C5C-0BB6BBB8125C"></endEvent>
    <sequenceFlow id="sid-B4C4F1DA-257B-4206-950A-133010C19C4A" sourceRef="sid-09FB7A15-7582-4785-B635-05E745D56438" targetRef="sid-6224E896-E5DF-4AD8-9C5C-0BB6BBB8125C"></sequenceFlow>
    <sequenceFlow id="sid-669C693E-E02E-47A1-B8EF-0F6DC4AEF61C" sourceRef="sid-431B47DD-3932-49D2-8B5A-51FBE9C8A50B" targetRef="sid-96F84EB8-DB79-4092-89A5-141313627020">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${day>1 && day<=3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-2498854B-52F3-4FCE-9994-B5ED2DC350E4" sourceRef="sid-431B47DD-3932-49D2-8B5A-51FBE9C8A50B" targetRef="sid-1728059A-DB68-4E2F-A07F-4AE72EC7F5D7">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${day<=1}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-9D85E323-099E-4F30-861E-0DED4491C1B8" sourceRef="sid-431B47DD-3932-49D2-8B5A-51FBE9C8A50B" targetRef="sid-09FB7A15-7582-4785-B635-05E745D56438">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${day}>3]]></conditionExpression>
    </sequenceFlow>
  </process>
 

</definitions>

部署这个a.bpmn20.xml文件:

 @Test
    void test01() {
        // 配置数据库相关信息 获取 ProcessEngineConfiguration
        ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
                .setJdbcUrl("jdbc:mysql://localhost:3306/tt?serverTimezone=UTC&nullCatalogMeansCurrent=true")
                .setJdbcUsername("root")
                .setJdbcDriver("com.mysql.cj.jdbc.Driver")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        // 获取流程引擎对象
        ProcessEngine processEngine = cfg.buildProcessEngine();

        // 部署流程 获取RepositoryService对象
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment()// 创建Deployment对象
                .addClasspathResource("a.bpmn20.xml") // 添加流程部署文件
                .name("请假") // 设置部署流程的名称
                .deploy(); // 执行部署操作
                }

测试执行:

 Map<String, Object> variables = new HashMap<>();
        //days是流程图条件
        
        variables.put("day", 3);
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("a", variables);
        System.out.println(pi.getName());

我们分别调整day为1,3,5时,此时ACT_RU_TASK表(ACT_RU_TASK表存储了运行时的用户任务数据)中将有三条数据:
在这里插入图片描述

  • 18
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
集成 Flowable 可以让 Spring Boot 应用程序具有工作流功能。下面是在 Spring Boot集成 Flowable 的步骤: 1. 添加依赖。在 pom.xml 文件中添加以下依赖: ``` <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>6.5.0</version> </dependency> ``` 2. 配置数据源。在 application.properties 文件中添加以下配置: ``` spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/flowable?useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=root ``` 3. 创建流程定义。在 resources 目录下创建一个名为 processes 的目录,然后在该目录下创建一个名为 myprocess.bpmn20.xml 的文件,该文件包含要创建的流程定义。 4. 创建 Service。创建一个名为 MyService 的类,并在该类中添加以下代码: ``` @Service public class MyService { @Autowired private RuntimeService runtimeService; public void startProcess(String processDefinitionKey) { runtimeService.startProcessInstanceByKey(processDefinitionKey); } } ``` 5. 创建 Controller。创建一个名为 MyController 的类,并在该类中添加以下代码: ``` @RestController @RequestMapping("/my") public class MyController { @Autowired private MyService myService; @PostMapping("/start-process") public void startProcess(@RequestParam("processDefinitionKey") String processDefinitionKey) { myService.startProcess(processDefinitionKey); } } ``` 6. 启动应用程序。运行 Spring Boot 应用程序。 现在,您已经成功在 Spring Boot集成Flowable,并可以使用工作流功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

π克

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值