spring:
datasource:
first:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: xxxx
username: xxxx
password:xxxx
second:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: xxxx
username: xxxx
password:xxxx
third:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: xxxx
username: xxxx
password:xxxx4
town: 三林镇
#sql日志打印
logging:
level:
com.dmo.busView.mapper: debug
配置文件:
@Configuration
@MapperScan(basePackages = "com.dmo.busView.mapper.infoissue", sqlSessionTemplateRef = "firstSqlSessionTemplate")
public class FirstDataSourceConfig {
@Bean(name = "firstDataSource")
@ConfigurationProperties(prefix = "spring.datasource.first")
@Primary
public DataSource firstDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "firstSqlSessionFactory")
@Primary
public SqlSessionFactory firstSqlSessionFactory(@Qualifier("firstDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
return bean.getObject();
}
@Bean(name = "firstTransactionManager")
@Primary
public DataSourceTransactionManager firstTransactionManager(@Qualifier("firstDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "firstSqlSessionTemplate")
@Primary
public SqlSessionTemplate firstSqlSessionTemplate(@Qualifier("firstSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
另外两个模仿这个配置文件