DataBaseConfig中加入事务管理器
DataBaseConfig的详解以及多数据源的配置参见我的上一篇文章
@Configuration@MapperScan(basePackages={"com.sc.myboot.dao"},sqlSessionFactoryRef = "MySqlSessionFactory1")public class DataBaseConfig { @Value("${spring.datasource.type}") private Class dataSourceType; @Bean(name = "MyDataSource1") @ConfigurationProperties(prefix = "data2") public DataSource getDataSource(){ return DataSourceBuilder.create().type(dataSourceType).build(); } @Bean(name = "Data1TransactionManager1") public DataSourceTransactionManager masterTransactionManager() { return new DataSourceTransactionManager(getDataSource()); } @Bean(name = "MySqlSessionFactory1") public SqlSessionFactory masterSqlSessionFactory(@Qualifier("MyDataSource1") DataSource masterDataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(masterDataSource); return sessionFactory.getObject(); }}