去年在参与某供应链管理系统改造时,我们需要为业务部门提供可视化的流程设计能力。传统基于XML定义流程的方式对业务人员门槛太高,而完整部署Flowable官方提供的独立Modeler又存在系统割裂问题。最终我们选择将Flowable Modeler直接嵌入SpringBoot应用,实现无缝集成。
这种方案的核心优势在于:
在实现流程可视化设计时,我们主要考虑过三种方案:
| 方案 | 优点 | 缺点 | 适用场景 |
|---|---|---|---|
| 独立部署Flowable-UI | 功能完整,官方维护 | 需要单独部署,用户体系隔离 | 大型企业多系统共用 |
| 基于BPMN.js二次开发 | 高度定制化 | 开发成本高,功能不完整 | 特殊流程设计需求 |
| 嵌入Modeler模块 | 无缝集成,维护成本低 | 需要解决静态资源冲突 | 单一系统深度集成 |
选择嵌入方案需要解决几个关键问题:
首先在pom.xml中添加必要依赖:
xml复制<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-rest</artifactId>
<version>6.7.2</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-conf</artifactId>
<version>6.7.2</version>
</dependency>
注意:建议保持Flowable各组件版本一致,避免因版本差异导致兼容性问题
在application.properties中配置静态资源映射:
properties复制spring.mvc.static-path-pattern=/static/**
spring.web.resources.static-locations=classpath:/static/,classpath:/META-INF/resources/flowable-ui/
创建Web配置类处理资源路径:
java复制@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/editor/**")
.addResourceLocations("classpath:/static/editor/");
}
}
重写Flowable的SecurityConfiguration:
java复制@Configuration
@EnableWebSecurity
public class CustomSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/modeler/**").hasRole("PROCESS_DESIGNER")
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login");
}
}
实现自定义的ModelService:
java复制@Service
public class CustomModelServiceImpl extends ModelServiceImpl {
@Override
public Model saveModel(Model model) {
// 添加业务系统特有的元数据
model.setMetaInfo(addBusinessMetadata(model));
return super.saveModel(model);
}
private String addBusinessMetadata(Model model) {
JSONObject metaInfo = new JSONObject();
metaInfo.put("createdBy", SecurityUtils.getCurrentUserId());
metaInfo.put("department", getCurrentDepartment());
return metaInfo.toString();
}
}
通过webpack打包优化前端资源:
配置示例:
javascript复制// vue.config.js
module.exports = {
configureWebpack: {
optimization: {
splitChunks: {
chunks: 'async',
minSize: 30000,
maxSize: 244000,
cacheGroups: {
bpmn: {
test: /[\\/]node_modules[\\/]bpmn-js[\\/]/,
priority: 10
}
}
}
}
}
}
添加自定义属性面板:
javascript复制export default function CustomPropertiesProvider(propertiesPanel) {
propertiesPanel.registerProvider(500, this);
this.getGroups = function(element) {
return function(groups) {
groups.push(createBusinessGroup(element));
return groups;
}
};
}
典型表现:
排查步骤:
解决方案:
bash复制# 查看jar包内容结构
jar tf target/your-app.jar | grep flowable-ui
当前端单独部署时可能遇到的CORS问题,解决方案:
java复制@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("http://frontend-domain")
.allowedMethods("GET", "POST");
}
}
多人协作时的版本控制方案:
核心代码实现:
java复制@Transactional
public Model updateModel(String modelId, Model newModel) {
Model current = modelRepository.findById(modelId);
if (current.getVersion() != newModel.getVersion()) {
throw new VersionConflictException();
}
// ...更新逻辑
}
添加Prometheus监控指标:
java复制@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> registry.config().commonTags(
"application", "flowable-modeler",
"region", System.getenv("REGION"));
}
关键监控指标:
必要的安全配置:
安全配置示例:
properties复制# 限制上传的BPMN文件大小
spring.servlet.multipart.max-file-size=1MB
spring.servlet.multipart.max-request-size=1MB
# 启用HTTPS
server.ssl.enabled=true
在我们供应链系统中实施后,业务部门的流程设计效率提升了60%。设计到部署的平均周期从原来的3天缩短到1天内。目前还在持续优化几个方向:
对于想要尝试这种集成方案的团队,建议先从测试环境开始,逐步验证以下关键点: