我是靠谱客的博主 震动枕头,这篇文章主要介绍spring boot多数据库数据源启动报错“required a single bean, but 2 were found”的正确解决办法,现在分享给大家,希望可以做个参考。
报错
Parameter 0 of method jdbcTemplate in org.springframework.boot.autoconfigure.jdbc.JdbcTemplateConfiguration required a single bean, but 2 were found:
- primaryDataSource: defined by method 'dataSource' in class path resource [com/xxx/xxx/base/infra/config/PrimaryDataSourceConfig.class]
- shardingSphereDataSource: defined by method 'dataSource' in class path resource [com/xxx/xxx/ShardingDataSourceAutoConfiguration.class]
解决方法:
1.启动类加:
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
或者
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
2.在其中一个datesource上添加 @Primary注解
最后
以上就是震动枕头最近收集整理的关于spring boot多数据库数据源启动报错“required a single bean, but 2 were found”的正确解决办法的全部内容,更多相关spring内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复