使用Camunda
配置双数据源不是必须的,因为Camunda
表的命名方式和自己的方式有区别,而且放在一起显得比较乱,所以将Camunda
的表单独存放。
首先多数据源配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| spring: datasource: primary: driver-class-name: com.p6spy.engine.spy.P6SpyDriver url: jdbc:p6spy:mariadb://192.168.10.65:3306/am_server?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull username: root password: 123456 camunda: driver-class-name: com.p6spy.engine.spy.P6SpyDriver url: jdbc:p6spy:mariadb://192.168.10.65:3306/camunda?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull username: root password: 123456
|
然后新建一个配置类
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 66 67 68 69 70 71 72 73 74
| import com.zaxxer.hikari.HikariDataSource; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.util.StringUtils;
import javax.sql.DataSource;
@Slf4j @Configuration public class DataSourceConfig {
@Primary @Bean(name = "primaryDataSourceProperties") @ConfigurationProperties(prefix = "spring.datasource.primary") public DataSourceProperties primaryDataSourceProperties() { return new DataSourceProperties(); }
@Primary @Bean(name = "primaryDataSource") @ConfigurationProperties(prefix = "spring.datasource.primary.hikari") public DataSource primaryDataSource() { DataSourceProperties properties = this.primaryDataSourceProperties(); return createHikariDataSource(properties); }
@Bean(name = "camundaDataSourceProperties") @ConfigurationProperties(prefix = "spring.datasource.camunda") public DataSourceProperties camundaDataSourceProperties() { return new DataSourceProperties(); }
@Bean(name = "camundaBpmDataSource") @ConfigurationProperties(prefix = "spring.datasource.camunda.hikari") public DataSource camundaDataSource() { log.info("---工作流数据源加载成功!---"); DataSourceProperties properties = this.camundaDataSourceProperties(); return createHikariDataSource(properties); }
private static HikariDataSource createHikariDataSource(DataSourceProperties properties) { HikariDataSource dataSource = properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); if (StringUtils.hasText(properties.getName())) { dataSource.setPoolName(properties.getName()); } return dataSource; } }
|
启动项目。