当前位置:   article > 正文

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

springboot集成flowableui

一、项目场景:

提示:使用版本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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6


可以看到没有集成和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
  • 2
  • 3
  • 4
  • 5
  • 6

三、问题总结:

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

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

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

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

解决方案:将FlowableUiSecurityAutoConfiguration排除

@SpringBootApplication(exclude = {FlowableUiSecurityAutoConfiguration.class})
  • 1

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.
  • 1

解决方案:参考flowable flowable-ui-modeler-conf组件中的源码中的配置类扫描我们需要的注入的类所在的包即可:
添加ModelerBeanConfig.java配置类到项目任意位置:

import org.flowable.ui.common.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.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;

/**
 * Greated by xiang on 2023/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.flowable.ui.common.conf", // flowable 开发环境内置的数据库连接
//       "org.flowable.ui.common.filter",// IDM 方面的过滤器
//       "org.flowable.ui.common.service",
        "org.flowable.ui.common.repository",
//       "org.flowable.ui.common.security",//授权方面的都不需要
//       "org.flowable.ui.common.tenant"
}, excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ModelRepositoryImpl.class)})
@EnableConfigurationProperties({FlowableCommonAppProperties.class})
public class ModelerBeanConfig {
    @Bean
    public ModelService createModelService() {
        return new ModelServiceImpl();
    }

    @Bean
    public ModelImageService createModelImageService() {
        return new ModelImageService();
    }

    @Bean
    public FlowableModelQueryService createFlowableModelQueryService() {
        return new FlowableModelQueryService();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

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: 2023/2/28 15:16
 */
@Configuration
public class FlowBpmnConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

    @Autowired
    private CustomDeploymentCache customDeploymentCache;
    @Autowired
    private CustomProcessDefinitionInfoCache customProcessDefinitionInfoCache;

    @Override
    public void configure(SpringProcessEngineConfiguration configuration) {
        configuration.setEnableProcessDefinitionInfoCache(true);
        configuration.setProcessDefinitionCache(customDeploymentCache);
        configuration.setProcessDefinitionInfoCache(customProcessDefinitionInfoCache);
        //设置自定义的uuid生成策略
        configuration.setIdGenerator(uuidGenerator());
    }

    @Bean
    public ProcessValidatorFactory processValidator(){
        return new ProcessValidatorFactory();
    }

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper();
    }


    @Bean
    public UuidGenerator uuidGenerator() {
        return new UuidGenerator();
    }

    /**
     * BpmnXMLConverter
     *
     * @return BpmnXMLConverter
     */
    @Bean
    public BpmnXMLConverter createBpmnXMLConverter() {
        return new BpmnXMLConverter();
    }

    /**
     * 在配置文件中如果没有字段,使用@Value的时候就会忽略掉,不会报错
     *
     * @return
     */
    @Bean
    public 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);
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
import org.flowable.common.engine.impl.persistence.StrongUuidGenerator;

/**
 * 功能描述: <br>
 * 〈uuid生成规则〉
 * @Author: 85122
 * @Date: 2023/2/28 15:16
 */
public class UuidGenerator extends StrongUuidGenerator {

    @Override
    public String getNextId() {
        String uuid = super.getNextId();
        uuid = uuid.replaceAll("-", "");
        return uuid;
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache;
import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Component;

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
 */
@Component
public class CustomDeploymentCache implements DeploymentCache<ProcessDefinitionCacheEntry> {

    protected String id;
    protected ProcessDefinitionCacheEntry entry;

    @Override
    public ProcessDefinitionCacheEntry get(String id) {
        if (id.equals(this.id)) {
            return entry;
        }
        return null;
    }

    @Override
    public void add(String id, ProcessDefinitionCacheEntry object) {
        this.id = id;
        this.entry = object;
    }

    @Override
    public void remove(String id) {
        if (id.equals(this.id)) {
            this.id = null;
            this.entry = null;
        }
    }

    @Override
    public void clear() {
        this.id = null;
        this.entry = null;
    }

    @Override
    public boolean contains(String id) {
        return id.equals(this.id);
    }

    @Override
    public Collection<ProcessDefinitionCacheEntry> getAll() {
        if (entry != null) {
            return Collections.singletonList(entry);
        } else {
            return new ArrayList<>();
        }
    }

    @Override
    public int size() {
        if (entry != null) {
            return 1;
        } else {
            return 0;
        }
    }

    // For testing purposes only
    public ProcessDefinition getCachedProcessDefinition() {
        if (entry == null) {
            return null;
        }
        return entry.getProcessDefinition();
    }

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache;
import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionInfoCacheObject;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class CustomProcessDefinitionInfoCache implements DeploymentCache<ProcessDefinitionInfoCacheObject> {

    private final Map<String, ProcessDefinitionInfoCacheObject> cache = new ConcurrentHashMap<>();

    @Override
    public ProcessDefinitionInfoCacheObject get(String id) {
        return cache.get(id);
    }

    @Override
    public boolean contains(String id) {
        return cache.containsKey(id);
    }

    @Override
    public void add(String id, ProcessDefinitionInfoCacheObject object) {
        cache.put(id, object);
    }

    @Override
    public void remove(String id) {
        cache.remove(id);
    }

    @Override
    public void clear() {
        cache.clear();
    }

    @Override
    public Collection<ProcessDefinitionInfoCacheObject> getAll() {
        return cache.values();
    }

    @Override
    public int size(){
        return cache.size();
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

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

在这里插入图片描述

import org.flowable.ui.common.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)
@EnableWebSecurity
public class ModelerSecurityConfiguration {

    @Configuration
    @Order(SecurityConstants.MODELER_API_SECURITY_ORDER)
    public static class ModelerApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

        @Override
        protected 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();
        }

    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

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.flowable.ui.common.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: 2023/2/28 15:00
 */
@Configuration
public class DatabaseConfiguration {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DatabaseConfiguration.class);
    protected static final String LIQUIBASE_CHANGELOG_PREFIX = "ACT_DE_";

    @Bean
    public 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);
                }

            }

        }

    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/681158
推荐阅读
相关标签
  

闽ICP备14008679号