说明
人大金仓数据库和mysql数据库比较相似,部分语法也类似。activiti中默认集成的是mysql数据源,而且并没有集成过人大金仓数据库。所以想要集成人大金仓数据库就要将该类的的数据源配置到其中去。这里的思路就是在流程引擎初始化数据库datasource的时候将配置文件重写。在工作流源码中我们不难看出:SpringProcessEngineConfiguration是处理工作流引擎的配置类,所以我们将AbstractProcessEngineAutoConfiguration中的ActivitiDatasourceProperties重写即可。
附录:传送门----人大金仓数据库和mysql的语法。
1、pom文件
bash
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 工作流集成springboot基础包 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.1.0.M4</version>
</dependency>
<!-- 工作流生成流程图片支持包 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-image-generator</artifactId>
<version>7.1.0.M4</version>
</dependency>
<!-- 人大金仓驱动和数据库包 -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.9</version>
</dependency>
<dependency>
<groupId>cn.com.kingbase</groupId>
<artifactId>kingbase8</artifactId>
<version>8.6.0</version>
</dependency>
<!-- 阿里 druid 数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.3</version>
</dependency>
<!-- 配置文件支撑包 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>6.0.0</version>
</dependency>
2、application.yml
bash
spring:
datasource:
url: jdbc:kingbase8://127.0.0.1:54321/activiti_test?characterEncoding=UTF-8&serverTimezone=GMT%2B8
username: activiti
password: 123456
driver-class-name: com.kingbase8.Driver
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.kingbase8.Driver
test-while-idle: false
validation-query: select 1
#重要配置
activiti:
database-type: postgres
database-schema: public
database-schema-update: true
db-history-used: true
history-level: full
application:
name: activiti_demo
main:
allow-bean-definition-overriding: true
#分页支持
pagehelper:
helperDialect: postgresql
logging:
level:
org.activiti.engine.impl.persistence.entity: debug
3、配置类ActivitiConfig和ActivitiDatasourceProperties
bash
@Configuration
@AutoConfigureAfter({DataSourceAutoConfiguration.class})
@AutoConfigureBefore({JpaProcessEngineAutoConfiguration.class})
public class ActivitiConfig {
@Configuration
@EnableConfigurationProperties({ActivitiProperties.class})
public static class ActivitiConfiguration extends AbstractProcessEngineAutoConfiguration {
private ActivitiDatasourceProperties activitiDatasourceProperties;
public ActivitiDatasourceProperties getActivitiDatasourceProperties() {
return activitiDatasourceProperties;
}
@Autowired
public void setActivitiDatasourceProperties(ActivitiDatasourceProperties activitiDatasourceProperties) {
this.activitiDatasourceProperties = activitiDatasourceProperties;
}
@Bean
@ConditionalOnMissingBean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(DataSource dataSource,
PlatformTransactionManager transactionManager, SpringAsyncExecutor springAsyncExecutor)
throws IOException {
SpringProcessEngineConfiguration config = baseSpringProcessEngineConfiguration(dataSource,
transactionManager, springAsyncExecutor);
return config;
}
//重新构造数据源
private SpringProcessEngineConfiguration baseSpringProcessEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager, SpringAsyncExecutor springAsyncExecutor) {
SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setDataSource(dataSource);
config.setTransactionManager(transactionManager);
config.setAsyncExecutor(springAsyncExecutor);
config.setDatabaseType(this.activitiDatasourceProperties.getDatabaseType());
config.setDatabaseSchemaUpdate("true");
config.setAsyncExecutorActivate(false);
config.setAsyncExecutorCorePoolSize(1);
config.setAsyncExecutorMaxPoolSize(1);
return config;
}
}
}
bash
@ConfigurationProperties(prefix = "spring.activiti")
@Component
public class ActivitiDatasourceProperties {
private String databaseType;
public String getDatabaseType() {
return databaseType;
}
public void setDatabaseType(String databaseType) {
this.databaseType = databaseType;
}
}```