1.在application.yml配置新增的数据库
octmes:# 从数据源开关/默认关闭enabled: trueurl: jdbc:mysql://localhost:3306/octmes?useUnicode=true&characterEncoding=UTF-8username: rootpassword: root
2.在DataSourceType.java 设置数据库名称
/*** 主库*/MASTER,/*** 从库*/OCTMES
3.在DruidConfig.java中注册数据源
@Bean@ConfigurationProperties("spring.datasource.druid.octmes")@ConditionalOnProperty(prefix = "spring.datasource.druid.octmes", name = "enabled", havingValue = "true")public DataSource octmesDataSource(DruidProperties druidProperties){DruidDataSource dataSource = DruidDataSourceBuilder.create().build();return druidProperties.dataSource(dataSource);}@Bean(name = "dynamicDataSource")@Primarypublic DynamicDataSource dataSource(DataSource masterDataSource){Map<Object, Object> targetDataSources = new HashMap<>();targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);setDataSource(targetDataSources, DataSourceType.OCTMES.name(), "octmesDataSource");return new DynamicDataSource(masterDataSource, targetDataSources);}