在前三篇文章中,我们依次认识了 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 服务
- 下载 Flowable Modeler 的 WAR 包并部署到 Tomcat
- 配置跨域支持(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);

最低0.47元/天 解锁文章
5499

被折叠的 条评论
为什么被折叠?



