lyh
2025-06-27 f472efc9ad1f9bda645dd39b40607c5eabb73b47
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
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();
    }
}