The bean 'dataSource', defined in class path resource [org/apache/shardingsphere/shardingjdbc/spring/boot/SpringBootConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class] and overriding is disabled.
时间: 2023-09-23 09:03:42 浏览: 360
这个问题的原因是你在项目中定义了两个同名的数据源,一个是使用ShardingSphere的数据源,另一个是使用阿里巴巴的Druid数据源。由于默认情况下Spring不允许同名的bean存在,所以会报出这个错误。
解决这个问题的方法有两种:
1. 修改其中一个数据源的bean名字,以保证唯一性。
2. 在ShardingSphere的数据源配置中添加`@Primary`注解,告诉Spring优先使用这个数据源。例如:
```
@Primary
@Bean
public DataSource dataSource() {
// 配置ShardingSphere数据源
}
```
这样就可以解决这个问题了。
阅读全文
相关推荐





