Activiti配置整合到nacos

月半闌珊染琉璃發表於2020-11-05

通過配置類載入

@Configuration
public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {

/**
 *  customConfig
 */
@Autowired
private CustomConfig customConfig;
/**
 *
 * @return dataSource
 */
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource activitiDataSource() {
    DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
    dataSourceBuilder.driverClassName(customConfig.getType());
    dataSourceBuilder.url(customConfig.getUrl());
    dataSourceBuilder.username(customConfig.getUsername());
    dataSourceBuilder.password(customConfig.getPassword());
    return dataSourceBuilder.build();
}

/**
 *
 * @param transactionManager  
 * @param springAsyncExecutor 
 * @return springProcessEngineConfiguration 
 * @throws IOException ## 標題
 */
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(
        PlatformTransactionManager transactionManager,
        SpringAsyncExecutor springAsyncExecutor) throws IOException {

    return baseSpringProcessEngineConfiguration(
            activitiDataSource(),
            transactionManager,
            springAsyncExecutor);
}

}

因為nacos的yaml配置為

spring
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://192.168.2.6:3306/brain_ng?serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=false
username:
password:
需要另一個配置類載入並設定
@Data
@Configuration
@PropertySource(value = “bootstrap.yml”,encoding = “utf-8”)
public class CustomConfig implements Serializable {
/**
* url
*/
@Value("${spring.datasource.url}")
private String url;

/**
 *  username
 */
@Value("${spring.datasource.username}")
private String username;

/**
 *  password
 */
@Value("${spring.datasource.password}")
private String password;

/**
 * type
 */
@Value("${spring.datasource.type}")
private String type;

}
另nacos中需要新增的配置為
activiti:
database-schema-update: false
db-history-used: false
db-identity-used: false
在進行連線是,可能會報出db連線不到的異常,因為我整合所需的依賴是activiti6.0.0,需要對屬性表act_ge_property進行設定
INSERT INTO ACT_GE_PROPERTY VALUES (‘cfg.execution-related-entities-count’, ‘false’, 1);
INSERT INTO ACT_GE_PROPERTY VALUES (‘next.dbid’, ‘5001’, 3);
INSERT INTO ACT_GE_PROPERTY VALUES (‘schema.history’, ‘create(6.0.0.4)’, 1);
INSERT INTO ACT_GE_PROPERTY VALUES (‘schema.version’, ‘6.0.0.4’, 1);

依賴如下

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-spring-boot-starter-basic</artifactId>
        <version>${activiti.version}</version>
    </dependency>

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-engine</artifactId>
        <version>${activiti.version}</version>
    </dependency>

相關文章