1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > SpringBoot 集成Flowable设计器(Flowable-ui)

SpringBoot 集成Flowable设计器(Flowable-ui)

时间:2023-11-04 02:07:59

相关推荐

SpringBoot 集成Flowable设计器(Flowable-ui)

一、项目场景:

提示:使用版本6.7.0

公司使用前后端项目分离,前端使用bpmn插件生成bpmn xml文件,后端解析处理数据。今天主要介绍后端集成flowable设计器的过程中遇到的问题。

如需了解flowable框架集成请参考文档

Flowable BPMN 用户手册 (v 6.3.0)

二、集成过程

提示:项目中遇到的问题:

为什么需要自己集成Flowable设计器?因为SpringBoot提供的依赖只集成Flowable引擎模块,没有集成modeler模块。SpringBoot集成Flowable需要导入如下依赖:

<!-- flowable --><dependency><groupId>org.flowable</groupId><artifactId>flowable-spring-boot-starter-process</artifactId><version>${flowable.version}</version></dependency>

可以看到没有集成和modeler相关的依赖,如下是flowable源码中提供的流程设计器模块:

flowable-ui-modeler-conf:放置一些列的配置项

flowable-ui-modeler-frontend:前端

flowable-ui-modeler-logic:放置Service以及dao层

flowable-ui-modeler-rest:放置Controller层

因为只需要集成flowable操作model 接口相关组件,所以只需要集成logic模块即可,添加依赖如下:

<!-- 配置ui集成 --><dependency><groupId>org.flowable</groupId><artifactId>flowable-ui-modeler-logic</artifactId><version>${flowable.version}</version></dependency>

三、问题总结:

提示:这里填写问题的分析:

1、程序启动报错(mon.app.idm-url must be set)

`Failed to instantiate [org.mon.service.idm.RemoteIdmService]: Factory method 'remoteIdmService' threw exception; nested exception is java.lang.IllegalArgumentException: `mon.app.idm-url` must be set`

这个是由于flowable调用自己的用户权限导致的,如果把flowable集成自己的框架里面,就不需要用它自带的用户体现和权限了。

解决方案:将FlowableUiSecurityAutoConfiguration排除

@SpringBootApplication(exclude = {FlowableUiSecurityAutoConfiguration.class})

2、引入modelService报红,运行报错

Field modelService in com.nmb.zx.base.sys.flow.service.FlowModelInfoService required a bean of type 'org.flowable.ui.modeler.serviceapi.ModelService' that could not be found.

解决方案:参考flowable flowable-ui-modeler-conf组件中的源码中的配置类扫描我们需要的注入的类所在的包即可:

添加ModelerBeanConfig.java配置类到项目任意位置:

import org.mon.properties.FlowableCommonAppProperties;import org.flowable.ui.modeler.repository.ModelRepositoryImpl;import org.flowable.ui.modeler.service.FlowableModelQueryService;import org.flowable.ui.modeler.service.ModelImageService;import org.flowable.ui.modeler.service.ModelServiceImpl;import org.flowable.ui.modeler.serviceapi.ModelService;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.ponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.FilterType;/*** Greated by xiang on /2/27*/@Configuration@ComponentScan(value = {// "org.flowable.ui.modeler.conf", //不引入 conf"org.flowable.ui.modeler.repository","org.flowable.ui.modeler.service",//"org.flowable.ui.modeler.security",//授权方面的都不需要// "org.mon.conf", // flowable 开发环境内置的数据库连接// "org.mon.filter",// IDM 方面的过滤器// "org.mon.service","org.mon.repository",// "org.mon.security",//授权方面的都不需要// "org.mon.tenant"}, excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ModelRepositoryImpl.class)})@EnableConfigurationProperties({FlowableCommonAppProperties.class})public class ModelerBeanConfig {@Beanpublic ModelService createModelService() {return new ModelServiceImpl();}@Beanpublic ModelImageService createModelImageService() {return new ModelImageService();}@Beanpublic FlowableModelQueryService createFlowableModelQueryService() {return new FlowableModelQueryService();}}

mybatisPlus中添加配置

添加BPMN配置文件FlowBpmnConfig

import com.fasterxml.jackson.databind.ObjectMapper;import com.nmb.zx.base.core.config.flow.customcache.CustomDeploymentCache;import com.nmb.zx.base.core.config.flow.customcache.CustomProcessDefinitionInfoCache;import org.apache.ibatis.session.SqlSessionFactory;import org.flowable.bpmn.converter.BpmnXMLConverter;import org.flowable.spring.SpringProcessEngineConfiguration;import org.flowable.spring.boot.EngineConfigurationConfigurer;import org.flowable.validation.ProcessValidatorFactory;import org.mybatis.spring.SqlSessionTemplate;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;/*** 功能描述: <br>* 〈flowable配置〉* @Author: 85122* @Date: /2/28 15:16*/@Configurationpublic class FlowBpmnConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {@Autowiredprivate CustomDeploymentCache customDeploymentCache;@Autowiredprivate CustomProcessDefinitionInfoCache customProcessDefinitionInfoCache;@Overridepublic void configure(SpringProcessEngineConfiguration configuration) {configuration.setEnableProcessDefinitionInfoCache(true);configuration.setProcessDefinitionCache(customDeploymentCache);configuration.setProcessDefinitionInfoCache(customProcessDefinitionInfoCache);//设置自定义的uuid生成策略configuration.setIdGenerator(uuidGenerator());}@Beanpublic ProcessValidatorFactory processValidator(){return new ProcessValidatorFactory();}@Beanpublic ObjectMapper objectMapper() {return new ObjectMapper();}@Beanpublic UuidGenerator uuidGenerator() {return new UuidGenerator();}/*** BpmnXMLConverter** @return BpmnXMLConverter*/@Beanpublic BpmnXMLConverter createBpmnXMLConverter() {return new BpmnXMLConverter();}/*** 在配置文件中如果没有字段,使用@Value的时候就会忽略掉,不会报错** @return*/@Beanpublic static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();configurer.setIgnoreUnresolvablePlaceholders(true);return configurer;}@Bean(destroyMethod = "clearCache")@Qualifier("flowableModeler")public SqlSessionTemplate modelerSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory);}}

import mon.engine.impl.persistence.StrongUuidGenerator;/*** 功能描述: <br>* 〈uuid生成规则〉* @Author: 85122* @Date: /2/28 15:16*/public class UuidGenerator extends StrongUuidGenerator {@Overridepublic String getNextId() {String uuid = super.getNextId();uuid = uuid.replaceAll("-", "");return uuid;}}

import mon.engine.impl.persistence.deploy.DeploymentCache;import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry;import org.flowable.engine.repository.ProcessDefinition;import org.ponent;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;/*** Very simplistic cache implementation that only caches one process definition.* * @author Joram Barrez*/@Componentpublic class CustomDeploymentCache implements DeploymentCache<ProcessDefinitionCacheEntry> {protected String id;protected ProcessDefinitionCacheEntry entry;@Overridepublic ProcessDefinitionCacheEntry get(String id) {if (id.equals(this.id)) {return entry;}return null;}@Overridepublic void add(String id, ProcessDefinitionCacheEntry object) {this.id = id;this.entry = object;}@Overridepublic void remove(String id) {if (id.equals(this.id)) {this.id = null;this.entry = null;}}@Overridepublic void clear() {this.id = null;this.entry = null;}@Overridepublic boolean contains(String id) {return id.equals(this.id);}@Overridepublic Collection<ProcessDefinitionCacheEntry> getAll() {if (entry != null) {return Collections.singletonList(entry);} else {return new ArrayList<>();}}@Overridepublic int size() {if (entry != null) {return 1;} else {return 0;}}// For testing purposes onlypublic ProcessDefinition getCachedProcessDefinition() {if (entry == null) {return null;}return entry.getProcessDefinition();}}

import mon.engine.impl.persistence.deploy.DeploymentCache;import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionInfoCacheObject;import org.ponent;import java.util.Collection;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;@Componentpublic class CustomProcessDefinitionInfoCache implements DeploymentCache<ProcessDefinitionInfoCacheObject> {private final Map<String, ProcessDefinitionInfoCacheObject> cache = new ConcurrentHashMap<>();@Overridepublic ProcessDefinitionInfoCacheObject get(String id) {return cache.get(id);}@Overridepublic boolean contains(String id) {return cache.containsKey(id);}@Overridepublic void add(String id, ProcessDefinitionInfoCacheObject object) {cache.put(id, object);}@Overridepublic void remove(String id) {cache.remove(id);}@Overridepublic void clear() {cache.clear();}@Overridepublic Collection<ProcessDefinitionInfoCacheObject> getAll() {return cache.values();}@Overridepublic int size(){return cache.size();}}

3、启动后访问接口直接重定向到登录页面

import org.mon.security.SecurityConstants;import org.springframework.context.annotation.Configuration;import org.springframework.core.annotation.Order;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;/*** 说明:重构ModelerSecurity 绕过登录*/@Configuration(proxyBeanMethods = false)@EnableWebSecuritypublic class ModelerSecurityConfiguration {@Configuration@Order(SecurityConstants.MODELER_API_SECURITY_ORDER)public static class ModelerApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();successHandler.setTargetUrlParameter("redirectTo");http.headers().frameOptions().disable();http.csrf().disable().authorizeRequests().antMatchers("/**/**").permitAll().anyRequest().authenticated().and().httpBasic();}}}

4、运行成功请求接口

找不到act_de_model表,因为flowable将act_re_model改成了act_de_model表了,所以需要手动添加配置类生产act_de_model表:

import liquibase.Liquibase;import liquibase.database.Database;import liquibase.database.DatabaseConnection;import liquibase.database.DatabaseFactory;import liquibase.database.jvm.JdbcConnection;import liquibase.exception.DatabaseException;import liquibase.resource.ClassLoaderResourceAccessor;import org.mon.service.exception.InternalServerErrorException;import org.slf4j.LoggerFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import javax.sql.DataSource;/*** 功能描述: <br>* 〈生成ACT_DE_开头的数据表〉* @Param: * @param null* @Return:* @Author: 85122* @Date: /2/28 15:00*/@Configurationpublic class DatabaseConfiguration {private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DatabaseConfiguration.class);protected static final String LIQUIBASE_CHANGELOG_PREFIX = "ACT_DE_";@Beanpublic Liquibase liquibase(DataSource dataSource) {LOGGER.info("Configuring Liquibase");Liquibase liquibase = null;try {DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());liquibase = new Liquibase("META-INF/liquibase/flowable-modeler-app-db-changelog.xml", new ClassLoaderResourceAccessor(), database);liquibase.update("flowable");return liquibase;} catch (Exception e) {throw new InternalServerErrorException("Error creating liquibase database", e);} finally {closeDatabase(liquibase);}}private void closeDatabase(Liquibase liquibase) {if (liquibase != null) {Database database = liquibase.getDatabase();if (database != null) {try {database.close();} catch (DatabaseException e) {LOGGER.warn("Error closing database", e);}}}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。