flowable / flowable-engine

A compact and highly efficient workflow and Business Process Management (BPM) platform for developers, system admins and business users.
https://www.flowable.org
Apache License 2.0
7.86k stars 2.6k forks source link

主业务项目有3个以上数据源集成时存的问题 Problems in integrating multiple data sources during project implementation #3785

Open ruixule opened 10 months ago

ruixule commented 10 months ago

在 flowable springboot start中,当主要业务有3个以上的mysql 数据源时,在没有配置默认数据库的情况下, 给flowable 单独配置一个数据源, 为什么还会去找 业务的3个数据源呢?而不是使用自己的单独配置的数据源呢?

In the flowable spring boot start, when there are three or more MySQL data sources for the main business, without configuring a default database,

Why would you still look for three data sources for your business when configuring a separate data source for Flowable? Instead of using your own separately configured data source?

image image

longsebo commented 10 months ago

我是单独给它配数据源的 @Data @Configuration public class FlowableEngineConfig implements EngineConfigurationConfigurer { /**

ruixule commented 10 months ago

我是单独给它配数据源的 @DaTa @configuration public class FlowableEngineConfig implements EngineConfigurationConfigurer { /* jdbc 驱动类 / @value("${spring.datasource.driver-class-name}") private String jdbcDriver; / jdbc url / @value("${spring.datasource.url}") private String jdbcUrl; / jdbc 用户名 / @value("${spring.datasource.username}") private String jdbcUsername; / jdbc 密码 */ @value("${spring.datasource.password}") private String jdbcPassword; 。。。 @OverRide public void configure(SpringProcessEngineConfiguration engineConfiguration) { engineConfiguration.setActivityFontName("宋体"); engineConfiguration.setLabelFontName("宋体"); engineConfiguration.setAnnotationFontName("宋体"); engineConfiguration.setJdbcDriver(this.jdbcDriver); engineConfiguration.setJdbcUrl(this.jdbcUrl); engineConfiguration.setJdbcUsername(this.jdbcUsername); engineConfiguration.setJdbcPassword(this.jdbcPassword); engineConfiguration.setDatabaseSchemaUpdate(this.databaseSchemaUpdate); engineConfiguration.setAsyncExecutorActivate(this.asyncExecutorActivate); } 。。。

你这边是整合的flowable-spring-boot-starter 还是只是engine呢

ruixule commented 10 months ago

我是单独给它配数据源的 @DaTa @configuration public class FlowableEngineConfig implements EngineConfigurationConfigurer { /* jdbc 驱动类 / @value("${spring.datasource.driver-class-name}") private String jdbcDriver; / jdbc url / @value("${spring.datasource.url}") private String jdbcUrl; / jdbc 用户名 / @value("${spring.datasource.username}") private String jdbcUsername; / jdbc 密码 */ @value("${spring.datasource.password}") private String jdbcPassword; 。。。 @OverRide public void configure(SpringProcessEngineConfiguration engineConfiguration) { engineConfiguration.setActivityFontName("宋体"); engineConfiguration.setLabelFontName("宋体"); engineConfiguration.setAnnotationFontName("宋体"); engineConfiguration.setJdbcDriver(this.jdbcDriver); engineConfiguration.setJdbcUrl(this.jdbcUrl); engineConfiguration.setJdbcUsername(this.jdbcUsername); engineConfiguration.setJdbcPassword(this.jdbcPassword); engineConfiguration.setDatabaseSchemaUpdate(this.databaseSchemaUpdate); engineConfiguration.setAsyncExecutorActivate(this.asyncExecutorActivate); } 。。。

还有就是请问下,你是如何处理 业务库和flowable数据库 的事务管理的?一起会滚或者一起提交的呢

Luusa1988 commented 6 months ago

兄弟,问题解决了吗?切换+事务

fangweilovelife commented 6 months ago

整合的flowable-spring-boot-starter,我用的切面解决的数据源问题

fangweilovelife commented 5 months ago

package xxxx.flowable.config;

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import lombok.extern.slf4j.Slf4j; import org.flowable.common.engine.impl.AbstractEngineConfiguration; import org.flowable.common.engine.impl.EngineConfigurator; import org.flowable.engine.ProcessEngine; import org.flowable.eventregistry.spring.configurator.SpringEventRegistryConfigurator; import org.flowable.spring.SpringProcessEngineConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.sql.DataSource;

@Slf4j @Configuration public class FlowableConfig {

@Autowired
private DynamicRoutingDataSource dynamicRoutingDataSource;
@Bean
public EngineConfigurator customEngineConfigurator() {
    return new EngineConfigurator() {
        @Override
        public void beforeInit(AbstractEngineConfiguration engineConfiguration) {
            DataSource dataSource = dynamicRoutingDataSource.getDataSource("flowable");
            engineConfiguration.setDataSource(dataSource);

        }

        @Override
        public int getPriority() {
            // 返回的值越小,优先级越高。这里返回0,表示最高优先级。
            return 0;
        }

        @Override
        public void configure(AbstractEngineConfiguration processEngineConfiguration) {
            // 在这里添加你的自定义配置逻辑
            // 例如,可以设置自定义的表单类型解析器或自定义的脚本任务执行器

            System.out.println("Custom Engine Configurator with highest priority is being applied.");
        }
    };
}

@Bean
public SpringEventRegistryConfigurator customEventEngineConfigurator() {
    return new SpringEventRegistryConfigurator() {
        @Override
        public void beforeInit(AbstractEngineConfiguration engineConfiguration) {
            DataSource dataSource = dynamicRoutingDataSource.getDataSource("tenant");
            engineConfiguration.setDataSource(dataSource);

        }

        @Override
        public int getPriority() {
            // 返回的值越小,优先级越高。这里返回0,表示最高优先级。
            return 0;
        }

        @Override
        public void configure(AbstractEngineConfiguration processEngineConfiguration) {
            // 在这里添加你的自定义配置逻辑
            System.out.println("Custom Engine Configurator with highest priority is being applied.");
        }
    };
}
@Bean
public ProcessEngine processEngine(SpringProcessEngineConfiguration configuration) {
    // 将自定义的EngineConfigurator添加到SpringProcessEngineConfiguration
    configuration.getProcessEngineConfiguration().addConfigurator(customEngineConfigurator());
    configuration.getProcessEngineConfiguration().addConfigurator(customEventEngineConfigurator());
    // 构建并返回流程引擎
    return configuration.buildProcessEngine();
}

}

fangweilovelife commented 5 months ago

整合的flowable-spring-boot-starter,我用的切面解决的数据源问题

package xxx.flowable.config; import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component;

/**

NicooooChan commented 1 month ago

你用的是哪个版本,为啥我用的6.4.2这个版本还是不行

fangweilovelife commented 1 month ago

你用的是哪个版本,为啥我用的6.4.2这个版本还是不行

我用的工作流版本是6.8,切面应该可以。第一种方法我也能切过来