zhangherong
2025-06-25 23855599412c4d61b38d78f0f3abd3430a48b5b1
lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/config/FlowableConfig.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,68 @@
package org.jeecg.modules.flowable.config;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.flowable.eventregistry.impl.EventRegistryEngine;
import org.flowable.eventregistry.impl.EventRegistryEngineConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
@Configuration
public class FlowableConfig {
    @Value("${spring.datasource.dynamic.datasource.master.url}")
    private String jdbcUrl;
    @Value("${spring.datasource.dynamic.datasource.master.username}")
    private String jdbcUsername;
    @Value("${spring.datasource.dynamic.datasource.master.password}")
    private String jdbcPassword;
    @Value("${spring.datasource.dynamic.datasource.master.driver-class-name}")
    private String jdbcDriver;
    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(jdbcUsername);
        dataSource.setPassword(jdbcPassword);
        dataSource.setDriverClassName(jdbcDriver);
        return dataSource;
    }
    @Bean(name = "processEngine")
    @DependsOn("dataSource")
    public ProcessEngine createProcessEngine(DataSource dataSource) {
        StandaloneProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
        cfg.setDataSource(dataSource);
        cfg.setDatabaseType("mssql");
        // å¯ä»¥æ ¹æ®éœ€è¦æ·»åŠ æ›´å¤šé…ç½®
        cfg.setActivityFontName("宋体");
        cfg.setLabelFontName("宋体");
        cfg.setAnnotationFontName("宋体");
        // è®¾ç½®æ•°æ®åº“模式更新策略为自动更新
        cfg.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        return cfg.buildProcessEngine();
    }
    @Bean(name = "eventRegistryEngine")
    public EventRegistryEngine eventRegistryEngine(DataSource dataSource) {
        EventRegistryEngineConfiguration config = new EventRegistryEngineConfiguration();
        config.setDataSource(dataSource);
        //flase:activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常。(生产环境常用)
        //true: activiti会对数据库中所有表进行更新操作。如果表不存在,则自动创建。(开发时常用)
        config.setDatabaseSchemaUpdate("true");
        return config.buildEventRegistryEngine();
    }
}