Flowable 工作流引擎REST API 与 Spring Boot 整合指南

本文介绍了如何将Flowable工作流引擎与Spring Boot进行整合,通过添加RestResponseFactory和ContentTypeResolver来提供REST服务,并解决了中文乱码问题。详细讲述了配置过程,包括添加依赖、设置REST API及测试,提供了Postman测试集合的链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Flowable 工作流引擎与 Spring Boot 整合指南

前言

在Java世界中,Activiti 和 Flowable 是工作流引擎的主流选择。Flowable 是 Activiti 的一个分支,两者用法相似。理想情况下,工作流引擎应提供 REST API 服务,实现引擎与服务的分离,使业务能够直接通过调用 REST API 来控制工作流。

依赖

Flowable 的所有依赖都可以在 Maven Central 找到。以下是一些主要依赖:

Group IDArtifact ID说明
org.flowableflowable-spring-boot-starterSpring Boot Flowable 依赖
org.flowableflowable-spring-boot-starter-rest-apiSpring Boot Flowable 全部五个模块的 REST API 依赖(已废弃)
org.flowableflowable-spring-boot-starter-process-restSpring Boot Flowable 流程引擎 ProcessEngine REST API 依赖
org.flowableflowable-spring-boot-starter-dmn-restSpring Boot Flowable 决策引擎 DmnEngine REST API 依赖
org.flowableflowable-spring-boot-starter-cmmn-restSpring Boot Flowable CMMN 决策引擎 CMMNEngine API 依赖

与 Spring Boot 整合

以下是 pom.xml 文件的配置示例:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>org.unreal</groupId>
    <artifactId>flowable-rest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>parent</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-process-rest</artifactId>
            <version>${flowable.version}</version>
        </dependency>
    </dependencies>
</project>

增加 RestResponseFactory 和 ContentTypeResolver 提供 REST 服务

@Bean
public RestResponseFactory restResponseFactory() {
    return new RestResponseFactory(new ObjectMapper());
}

@Bean
public ContentTypeResolver contentTypeResolver() {
    return new DefaultContentTypeResolver();
}

解决中文乱码

@Bean
SpringProcessEngineConfiguration processEngineConfiguration(SimpleDriverDataSource dataSource, DataSourceTransactionManager transactionManager, FormEngineConfiguration formEngineConfiguration, IdmEngineConfiguration idmEngineConfiguration) throws IOException {
    SpringProcessEngineConfiguration cfg = new SpringProcessEngineConfiguration();
    cfg.setDataSource(dataSource).setDatabaseSchemaUpdate("true").setAsyncExecutorActivate(true);
    Resource[] resources = this.applicationContext.getResources("classpath:bpmn/process/*.bpmn20.xml");
    String classPath = ResourceUtils.getURL("classpath:").getPath();
    this.showResourceLog(resources);
    cfg.setDeploymentResources(resources);
    cfg.setTransactionManager(transactionManager);
    FormEngineConfigurator formEngineConfigurator = new FormEngineConfigurator();
    formEngineConfigurator.setFormEngineConfiguration(formEngineConfiguration);
    cfg.addConfigurator(formEngineConfigurator);
    IdmEngineConfigurator idmEngineConfigurator = new IdmEngineConfigurator();
    idmEngineConfigurator.setIdmEngineConfiguration(idmEngineConfiguration);
    cfg.addConfigurator(idmEngineConfigurator);
    cfg.setActivityFontName("宋体"); // Windows 下使用中文字体,Linux 需要换成支持中文的字体
    cfg.setLabelFontName("宋体");
    cfg.setAnnotationFontName("宋体");
    cfg.buildProcessEngine();
    return cfg;
}

使用

官方 Tomcat 部署方式需要使用 IDM 登录或在 REST API 上使用 Basic auth 来使用 REST 服务。但本文介绍的方式可以直接访问,不需要验证。默认端口是 8080,请求地址如下:

  • http://127.0.0.1:8080/process-api/

process-api 依赖了 flowable-spring-boot-starter-process-restdmn-api 需要依赖 flowable-spring-boot-starter-dmn-restcmmn-api 需要依赖 flowable-spring-boot-starter-cmmn-rest

REST API 文档

官方网站上有 REST API 的详细说明,请访问:

Flowable REST API Documentation

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值