springboot 2.6.13 整合flowable6.8.1

整理好springboot2.6.13 和flowable6.8.1 方便大家学习,使用

1.pom文件

2.application文件

3.工作流文件

4.controller

5.service

1.pom文件

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.13</version>
        <relativePath/>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>flowable-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>flowable</name>

    <!-- 依赖包 -->
    <properties>
        <flowable.version>6.8.1</flowable.version>
    </properties>
    <dependencies>
        <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>

        <!-- Flowable 核心模块 -->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-engine</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>
        <!-- thymeleaf架包 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-ui-task</artifactId>
            <version>${flowable.version}</version>
        </dependency>

        <!--mysql依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.27</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

2.application文件

复制代码
server:
  port: 9999

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/flowable_demo?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true
    username: root
    password: hilishuai
    driverClassName: com.mysql.cj.jdbc.Driver

  # Flowable 配置
flowable:
  # 数据库模式更新策略,可选值:false, true, create-drop, drop-create,生产环境建议false
  database-schema-update: true
  activity-font-name: 宋体
  label-font-name: 宋体
  annotation-font-name: 宋体
  process:
    # 流程定义缓存中保存流程定义的最大数量。默认值为-1(缓存所有流程定义)。
    definition-cache-limit: -1
  # 禁用异步执行器,开发和测试阶段可这样配置
  async-executor-activate: false
  # 历史数据级别,可选值:none, activity, audit, full
  history-level: full
  # 是否自动检查并部署流程文件,设置为false需要手动部署流程文件
  check-process-definitions: true


# MyBatis 配置
mybatis:
  type-aliases-package: com.example.demo.entity
  mapper-locations: classpath:mapper/*.xml

logging:
  level:
    com.example.demo: debug
    org.flowable: debug

3.工作流文件

复制代码
<?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:flowable="http://flowable.org/bpmn"
             typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
             targetNamespace="http://www.flowable.org/processdef">
    <!-- -请假条流程图 -->
    <process id="leaveRequestProcess" name="请假条流程" isExecutable="true">
        <!-- -流程的开始 -->
        <startEvent id="startEvent"/>
        <sequenceFlow sourceRef="startEvent" targetRef="approveTask"/>
        <!-- -流程的节点 -->
        <userTask id="approveTask" name="开始请假" flowable:candidateGroups="managers"/>
        <!-- -流程节点间的线条,上一个节点和下一个节点-->
        <sequenceFlow sourceRef="approveTask" targetRef="decision"/>
        <!-- -排他性网关 -->
        <exclusiveGateway id="decision"/>
        <!-- -同意时 -->
        <sequenceFlow sourceRef="decision" targetRef="holidayApprovedTask">
            <conditionExpression xsi:type="tFormalExpression">
                <![CDATA[${approved}]]>
            </conditionExpression>
        </sequenceFlow>
        <!-- -拒绝时 -->
        <sequenceFlow sourceRef="decision" targetRef="rejectEnd">
            <conditionExpression xsi:type="tFormalExpression">
                <![CDATA[${!approved}]]>
            </conditionExpression>
        </sequenceFlow>
        <!-- -外部服务 -->
        <!-- <serviceTask id="externalSystemCall" name="Enter holidays in external system"
                     flowable:class="org.javaboy.flowable02.flowable.Approve"/>
        <sequenceFlow sourceRef="externalSystemCall" targetRef="holidayApprovedTask"/> -->

        <userTask id="holidayApprovedTask" flowable:assignee="${employee}" name="同意请假"/>
        <sequenceFlow sourceRef="holidayApprovedTask" targetRef="approveEnd"/>

        <!-- <serviceTask id="rejectLeave" name="Send out rejection email"
                     flowable:class="org.javaboy.flowable02.flowable.Reject"/>
        <sequenceFlow sourceRef="rejectLeave" targetRef="rejectEnd"/> -->

        <endEvent id="approveEnd"/>

        <endEvent id="rejectEnd"/>
        <!-- -流程的结束 -->
    </process>
</definitions>

4.controller

复制代码
package com.example.demo.controller;

import com.example.demo.service.LeaveRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LeaveRequestController {

    @Autowired
    private LeaveRequestService leaveRequestService;

    @GetMapping("/deploy")
    public String deployLeaveRequest() {
        return "Process instance started with ID: " + leaveRequestService.deployLeaveRequestProcess();
    }

    @GetMapping("/start")
    public String startLeaveRequest() {
        return "Process instance started with ID: " + leaveRequestService.startLeaveRequestProcess();
    }

}

5.service

复制代码
package com.example.demo.service;

import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class LeaveRequestService {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    public String startLeaveRequestProcess() {
        Map<String, Object> variables = new HashMap();
        variables.put("employee", "John Doe");
        variables.put("leaveDays", 5);
        return runtimeService.startProcessInstanceByKey("leaveRequestProcess", variables).getId();
    }

    public String deployLeaveRequestProcess() {
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("processes/leaveProcess.bpmn20.xml")  // 确认文件路径正确
                .name("请假流程部署")
                .deploy(); // 执行部署
        System.out.println(deployment.toString());
        return deployment.getId();
    }
}

6.Application.java

复制代码
package com.example.demo;

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);
    }
}

方便学习使用,代码地址如下:

https://download.csdn.net/download/xiaowangzi756897098/92543670

相关推荐
Tao____14 小时前
基于Ruoyi开发的IOT物联网平台
java·网络·物联网·mqtt·网络协议
花哥码天下14 小时前
apifox登录后设置token到环境变量
java·后端
浩瀚地学15 小时前
【Java】常用API(二)
java·开发语言·经验分享·笔记·学习
hashiqimiya15 小时前
springboot事务触发滚动与不滚蛋
java·spring boot·后端
因我你好久不见16 小时前
Windows部署springboot jar支持开机自启动
windows·spring boot·jar
TeamDev16 小时前
基于 Angular UI 的 C# 桌面应用
前端·后端·angular.js
PPPHUANG16 小时前
一次 CompletableFuture 误用,如何耗尽 IO 线程池并拖垮整个系统
java·后端·代码规范