配置的内容有:DataSource, SqlSessionFactory, DataSourceTransactionManager和SqlSessionTemplate。多数据源的情况下,需要指定Primary。
@Configuration
//basePackages:mapper接口类所在的包路径
@MapperScan(basePackages = "com.yh.dwdatalink.common.dal.mysqldatalink.mapper", sqlSessionTemplateRef = "datalinkSqlSessionTemplate")
public class DataSouceDatalinkConfig {
private final String mybatisConfig = "classpath:mybatis/mysql-datalink-mybatis-config.xml";
private final String sqlmap = "classpath:sqlmap/mysqldatalink/*.xml";
@Bean(name = "datalinkDataSource")
@ConfigurationProperties(prefix = "spring.datasource.datalink")
@Primary
public DataSource datalinkDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "datalinkSqlSessionFactory")
@Primary
public SqlSessionFactory datasou