SpringBoot+flowable-ui集成实战

本文详细介绍了如何在SpringBoot项目中集成Flowable工作流引擎,包括Flowable API与UI的引入,数据库初始化,用户中心集成,动态数据源配置以及任务自动分配的实现。通过实例代码和配置解析,帮助读者理解如何在实际项目中应用Flowable。

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

前言

公司最近想要使用flowable作为我们工作流引擎,主要用于各类流程审批上。在网上搜索到了很多有参考意义的文章,但有些实现细节还需要自己去摸索。本文的实战包括:

  1. 在项目中引入flowable的包可以使用flowable的api;
  2. 将flowable-ui集成到自己项目里;
  3. 如何使用flowable-ui创建的流程模型(我们用的是bpmn模型,所以后面的提到的流程都是指bpmn);
  4. 集成公司的用户认证体系;
  5. 自动分配

sample源码地址: https://github.com/ChangeChe/flowable

flowable集成

flowable的集成有两部分:flowable-api与flowable-ui。flowable-api主要管创建好流程后怎么使用,flowable-ui就是通过页面去编排我们的流程。

jar包引入

这里的是较新的版本6.7.0。因为自身的框架用的是springboot,所以需要引入一个starter。引入的包里有flowable-ui-xxx是flowable-ui需要的包;其他是我们使用flowable-api需要的包。

<properties>
    <flowable.version>6.7.0</flowable.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter-process</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-idm-spring-configurator</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-json-converter</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-modeler-rest</artifactId>
        <version>${flowable.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.flowable</groupId>
                <artifactId>flowable-json-converter</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j2</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-modeler-conf</artifactId>
        <version>${flowable.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.flowable</groupId>
                <artifactId>flowable-json-converter</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-idm-conf</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-ui-idm-rest</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-form-engine</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-form-spring</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-form-engine-configurator</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-form-spring-configurator</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-app-engine</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
        <version>4.3.5</version>
        <exclusions>
            <exclusion>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

配置

# flowable配置
flowable.common.app.idm-url = /idm
flowable.modeler.app.rest-enabled = true
flowable.database-schema-update = true
flowable.process.definition-cache-limit = 1
flowable.xml.encoding = UTF-8

# mybatis配置
mybatis.mapper-locations = classpath:/META-INF/modeler-mybatis-mappings/*.xml
mybatis.config-location = classpath:/META-INF/mybatis-config.xml
mybatis.configuration-properties.blobType = BLOB
mybatis.configuration-properties.boolValue = TRUE
mybatis.configuration-properties.prefix = 

Web配置

路由

@Configuration
@EnableConfigurationProperties({FlowableIdmAppProperties.class, FlowableModelerAppProperties.class})
@ComponentScan(basePackages = {
        "org.flowable.ui.idm.conf",
//        "org.flowable.ui.idm.security",
        "org.flowable.ui.idm.service",
        "org.flowable.ui.modeler.repository",
        "org.flowable.ui.modeler.service",
//        "org.flowable.ui.common.filter",
        "org.flowable.ui.common.service",
        "org.flowable.ui.common.repository",
//        "org.flowable.ui.common.security",
        "org.flowable.ui.common.tenant",
        "org.flowable.form"
}, excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = org.flowable.ui.idm.conf.ApplicationConfiguration.class)
})
public class ApplicationConfiguration implements BeanPostProcessor {
    @Bean
    public ServletRegistrationBean apiServlet(ApplicationContext applicationContext) {
        AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
        dispatcherServletConfiguration.setParent(applicationContext);
        dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);
        DispatcherServlet servlet = new DispatcherServlet(dispatcherServ
<think>好的,我现在要解决SpringBoot整合Flowable-UI时出现404的问题。首先,我需要回忆一下Flowable-UI的基本配置步骤。记得Flowable-UI需要一些特定的依赖和配置,比如Spring Security的设置,可能还需要正确配置静态资源路径。 用户提到404错误,通常意味着资源未找到或者路由配置不正确。可能的原因包括依赖缺失、路径配置错误、过滤器拦截了请求,或者Spring Security没有正确放行相关路径。 首先检查pom.xml中的依赖是否正确。Flowable-UI通常需要引入flowable-ui-modeler、flowable-ui-common等依赖,同时确保Spring Boot版本兼容。如果依赖版本不匹配,可能导致类加载失败,进而引发404。 然后,查看应用配置文件,比如application.properties,确认是否启用了Flowable的REST API和UI。可能需要设置flowable.rest.app.enabled=true。另外,静态资源的路径可能需要调整,例如设置server.servlet.context-path=/flowable,这样访问路径会变成/flowable/ui,否则默认可能是根路径。 接下来,检查Spring Security配置。Flowable-UI有自己的安全配置,可能需要与项目中的Security配置进行整合。如果自定义了SecurityConfig,可能需要排除Flowable相关的路径,或者允许匿名访问这些路径。例如,在configure方法中添加antMatchers("/flowable-ui/**").permitAll()。 另外,检查日志是否有异常信息,比如Bean创建失败或者路径映射错误。有时候类冲突或缺少必要的Bean会导致UI模块无法正确初始化,从而无法注册控制器,导致404。 还有可能的是Servlet配置问题,比如缺少@ServletComponentScan注解,导致Flowable的Servlet或Filter没有被注册。确保主应用类上有这个注解,或者通过配置类显式注册相关组件。 最后,考虑版本兼容性问题。Spring Boot和Flowable的版本需要匹配,查看官方文档确认支持的版本。如果版本不兼容,某些类或配置可能无法加载,导致功能失效。 可能需要逐步排查:先确认依赖正确,再检查配置和路径,然后查看安全设置,最后验证版本兼容性。如果这些步骤都正确,可以尝试创建一个最简单的示例项目,逐步添加功能,找出导致404的具体原因。</think>### SpringBoot整合Flowable-UI出现404的解决方案 #### 1. 检查依赖配置 确保`pom.xml`中引入Flowable-UI的核心依赖且版本与SpringBoot兼容: ```xml <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-ui-modeler</artifactId> <version>6.7.2</version> </dependency> ``` **注意**:Flowable 6.x版本需与Spring Boot 2.x配合使用;若使用Spring Boot 3.x需升级到Flowable 7.0+[^1]。 #### 2. 配置静态资源路径 在`application.properties`中添加: ```properties # 启用Flowable REST API flowable.rest.app.enabled=true # 设置上下文路径(避免与现有接口冲突) server.servlet.context-path=/flowable ``` 访问地址将变为:`http://localhost:8080/flowable/ui` #### 3. 安全配置整合 在自定义的`SecurityConfig`类中放行Flowable路径: ```java @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/flowable-ui/**", "/api/**").permitAll() .anyRequest().authenticated() .and().csrf().disable(); } ``` #### 4. 添加Servlet扫描注解 在主启动类添加注解确保Flowable组件加载: ```java @ServletComponentScan("org.flowable.ui") @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` #### 5. 日志排查 检查启动日志中是否包含以下关键信息: ``` Mapped URL path [/flowable-ui] onto handler... Flowable UI applications available at [/ui] ``` 若缺失则说明路由注册失败,需检查Filter配置或依赖冲突。 #### 典型错误场景示例 某开发者因未配置`server.servlet.context-path`导致实际访问路径为`http://localhost:8080/ui`,而服务器预期路径为`http://localhost:8080/flowable/ui`,最终通过明确上下文路径解决404问题[^2]。
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值