报错误:
Field masterDB in com.happylaishop.shop.web.DataSourceConfig.MybatisConfig required a single bean, but 3 were found:
- masterDB: defined by method 'dataSource' in class path resource [com/happylaishop/shop/web/DataSourceConfig/DatasourceConfig.class]
- slaveDB: defined by method 'dataSourceSlave' in class path resource [com/happylaishop/shop/web/DataSourceConfig/DatasourceConfig.class]
- dynamicDataSource: defined by method 'dynamicDataSource' in class path resource [com/happylaishop/shop/web
2.我的解决方法:
首先在springboot上配置
@SpringBootApplication(exclude= {
DataSourceAutoConfiguration.class
})
3.后台报错:
No qualifying bean of type 'transaction.PlatformTransactionManager' available
解决方法:
在配置动态数据源的类:Mybatisconfig.java中加入事务管理。
@Bean
public DataSourceTransactionManager transactitonManager(){
return new DataSourceTransactionManager(dynamicDataSource());
}
4.老大我这样配置后不报错了。报错也没问题:
插入库后,用int a = 1/0;报异常测试事务回滚正常。
5.老大看看配置对不对,还缺什么,补全一下。
登录后可查看更多问答,登录/注册