JEECG Boot整合Flowable 6.5.0实战:从权限配置到流程发布的完整避坑指南
JEECG Boot深度整合Flowable 6.5.0全流程实战:从权限体系设计到流程引擎调优
当企业级应用需要引入工作流引擎时,JEECG Boot与Flowable的整合往往成为Java开发团队的首选方案。这种组合既能享受JEECG快速开发的优势,又能获得Flowable强大的流程管理能力。但在实际落地过程中,开发者常会遇到权限体系冲突、用户身份识别异常、前后端对接不畅等典型问题。本文将基于6.5.0版本,分享一套经过生产验证的整合方案。
1. 工程架构设计与核心依赖配置
1.1 子模块化工程结构规划
推荐采用Maven多模块架构,将Flowable相关功能独立为子模块。这种设计既保持了解耦性,又便于后续扩展。在父工程pom.xml中定义版本管理:
<properties> <flowable.version>6.5.0</flowable.version> </properties>子模块需引入的关键依赖包括:
<dependencies> <!-- JEECG基础依赖 --> <dependency> <groupId>org.jeecgframework.boot</groupId> <artifactId>jeecg-boot-base-common</artifactId> </dependency> <!-- Flowable核心引擎 --> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>${flowable.version}</version> </dependency> <!-- 模型设计器REST API --> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-ui-modeler-rest</artifactId> <version>${flowable.version}</version> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </exclusion> </exclusions> </dependency> <!-- 管理控制台配置 --> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-ui-admin-conf</artifactId> <version>${flowable.version}</version> </dependency> </dependencies>1.2 数据库连接特殊配置
Flowable对数据库元数据获取有特殊要求,需在JDBC URL中添加关键参数:
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/jeecg-boot?nullCatalogMeansCurrent=true&characterEncoding=UTF-8注意:
nullCatalogMeansCurrent=true参数对MySQL连接至关重要,缺失会导致Flowable启动时无法正确识别数据库表结构。
2. 权限体系深度整合方案
2.1 解决anonymousUser身份问题
原生Flowable与JEECG的Shiro权限体系存在冲突,直接集成会导致流程发起人显示为anonymousUser。我们需要重写身份获取逻辑:
@Component public class FlowableStartedListener implements ApplicationListener<ContextRefreshedEvent>{ @Override public void onApplicationEvent(ContextRefreshedEvent event) { Authentication.setAuthenticationContext(new MyAuthenticationContext()); } } public class MyAuthenticationContext implements AuthenticationContext { @Override public String getAuthenticatedUserId() { // 与JEECG的Shiro体系对接 LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal(); return sysUser != null ? sysUser.getId() : null; } }2.2 安全配置优化
关闭CSRF防护并配置URL白名单:
@Configuration @EnableWebSecurity public class FlowbleSecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .antMatchers("/flowable/**", "/app/**").permitAll() .anyRequest().authenticated(); } @Bean public HttpFirewall allowUrlEncodedSlashHttpFirewall() { return new DefaultHttpFirewall(); } }关键配置项说明:
| 配置项 | 作用 | 推荐值 |
|---|---|---|
| csrf().disable() | 关闭跨站请求伪造防护 | 必须关闭 |
| antMatchers() | 开放Flowable相关路径 | /flowable/** |
| HttpFirewall | 允许URL特殊字符 | 必须配置 |
3. 流程模型发布与部署实战
3.1 增强型流程发布控制器
原生模型发布接口往往不能满足企业需求,我们需要扩展发布逻辑:
@RestController @RequestMapping("/app") public class MyModelResources { @Autowired private RepositoryService repositoryService; @PostMapping("publish/{modelId}") public JSONObject publish(@PathVariable String modelId) { Model model = modelService.getModel(modelId); BpmnModel bpmnModel = modelService.getBpmnModel(model); Deployment deployment = repositoryService.createDeployment() .addBpmnModel(model.getName() + ".bpmn20.xml", bpmnModel) .name(model.getName()) .key(model.getKey()) .tenantId(model.getTenantId()) .deploy(); JSONObject result = new JSONObject(); result.put("deploymentId", deployment.getId()); result.put("deploymentTime", deployment.getDeploymentTime()); return result; } }3.2 流程定义缓存处理
高频发布时需注意缓存清理:
// 发布后清理缓存 repositoryService.createDeploymentQuery() .deploymentId(deploymentId) .singleResult(); processEngine.getProcessEngineConfiguration() .getProcessDefinitionCache() .clear();4. 前端深度整合方案
4.1 模型设计器嵌入技巧
将Flowable Modeler整合到JEECG前端框架时,需要注意:
- 静态资源放置到
public/flowable目录 - 修改
app-cfg.js中的基础路径配置 - 添加Token传递拦截器:
// providers-config.js request: function(config) { config.headers = config.headers || {}; if (localStorage.getItem('pro__Access-Token')) { config.headers['X-Access-Token'] = JSON.parse(localStorage.getItem('pro__Access-Token')).value; } return config; }4.2 Vue组件封装方案
创建可复用的流程设计器组件:
<template> <div class="flowable-container"> <iframe src="/flowable/index.html" :style="iframeStyle" @load="onIframeLoad"> </iframe> </div> </template> <script> export default { data() { return { iframeStyle: { width: '100%', height: 'calc(100vh - 180px)', border: 'none' } } }, methods: { onIframeLoad() { console.log('Flowable designer loaded'); } } } </script>5. 生产环境调优建议
5.1 性能关键参数配置
在application.yml中添加Flowable性能配置:
flowable: async-executor-activate: true async-executor: core-pool-size: 10 max-pool-size: 50 queue-size: 1000 process: definition-cache-limit: 1005.2 历史数据归档策略
对于高频流程系统,建议配置历史数据清理:
-- 创建归档表 CREATE TABLE ACT_HI_PROCINST_ARCH LIKE ACT_HI_PROCINST; -- 设置自动归档任务 flowable: history-level: audit history-cleanup: enabled: true batch-size: 100 time-window: P30D在实际项目落地过程中,我们发现最大的挑战往往不在于技术实现,而在于权限体系的无缝对接。通过重写SecurityUtils和AuthenticationContext,我们成功解决了JEECG与Flowable的身份识别冲突问题。对于需要深度定制的团队,建议重点关注流程节点与JEECG权限标签的联动设计。
