Flowable 与 Spring Boot 深度集成:从环境搭建到平台构建

该文章已生成可运行项目,

在前三篇文章中,我们依次认识了 Flowable 的基础概念、用 Modeler 设计流程,以及通过 API 控制流程运行。但在实际项目中,我们更需要将 Flowable 与 Spring Boot 深度融合,构建完整的工作流平台。本文将从环境配置、设计器集成、权限控制等方面,分享 Flowable 与 Spring Boot 集成的实战经验。

一、Flowable 与 Spring Boot 的无缝对接

1.1 基础环境配置

Spring Boot 对 Flowable 提供了自动配置支持,只需引入相关依赖即可快速集成:

<dependencies>
    <!-- Flowable核心依赖 -->
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter</artifactId>
        <version>6.8.0</version>
    </dependency>
    
    <!-- Web依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <!-- 数据库依赖 -->
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    <!-- 安全框架(用于权限控制) -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
</dependencies>

在application.yml中配置数据库和 Flowable 参数:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/flowable_boot?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver

flowable:
  # 数据库表结构更新策略
  database-schema-update: true
  # 异步执行器配置
  async-executor-activate: true
  # 历史记录级别
  history-level: full
  # 流程部署路径
  process-definition-location-prefix: classpath:/processes/

1.2 自定义 Flowable 配置

通过ProcessEngineConfigurationConfigurer可自定义流程引擎配置:

@Configuration
public class FlowableConfig implements ProcessEngineConfigurationConfigurer {

    @Override
    public void configure(SpringProcessEngineConfiguration configuration) {
        // 配置邮件服务器(用于任务通知)
        configuration.setMailServerHost("smtp.example.com");
        configuration.setMailServerPort(587);
        configuration.setMailServerUsername("notifications@example.com");
        configuration.setMailServerPassword("password");
        
        // 配置自定义表单类型
        List<AbstractFormType> customFormTypes = new ArrayList<>();
        customFormTypes.add(new PhoneFormType()); // 自定义手机号表单类型
        customFormTypes.add(new IdCardFormType()); // 自定义身份证表单类型
        configuration.setCustomFormTypes(customFormTypes);
        
        // 配置流程自动部署器
        configuration.setDeploymentName("spring-boot-deployment");
    }
}

二、Flowable Modeler 与业务系统集成

将 Flowable Modeler 嵌入业务系统,实现流程设计与业务的无缝衔接。

2.1 部署独立的 Modeler 服务

  1. 下载 Flowable Modeler 的 WAR 包并部署到 Tomcat
  2. 配置跨域支持(flowable-modeler-app/WEB-INF/classes/flowable-modeler.properties):
flowable.modeler.app.cors.allowed-origins=http://localhost:8080

flowable.modeler.app.cors.allowed-methods=GET,POST,PUT,DELETE,OPTIONS

flowable.modeler.app.cors.allowed-headers=Content-Type,Authorization

 3.配置与业务系统相同的数据库,实现数据共享

2.2 实现 Modeler 与业务系统的单点登录

通过自定义过滤器实现 SSO 集成:

@Component
public class ModelerSsoFilter extends OncePerRequestFilter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    protected void doFilterInternal(HttpServletRequest request, 
                                   HttpServletResponse response, 
                                   FilterChain filterChain) throws ServletException, IOException {
        
        // 从请求头获取令牌
        String token = request.getHeader("Authorization");
        if (token != null && token.startsWith("Bearer ")) {
            try {
                // 验证令牌并创建认证对象
                UsernamePasswordAuthenticationToken authToken = 
                    new UsernamePasswordAuthenticationToken(token, token);
  
本文章已经生成可运行项目
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

程序员小胡12138

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

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

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

打赏作者

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

抵扣说明:

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

余额充值