The bean ‘xxxRepository’, defined in xxx defined in @EnableJpaRepositories declared on PropertyConfig, could not be registered. A bean with that name has already been defined in cn.xfdc.shopproject.repository.property.xxxy defined in @EnableJpaRepositories declared on DataSourceConfig and overriding is disabled.
查到问题 说 'xxx’扫描重复
刚开始分析时以为SpringBoot本身具有自动配置,现在自动配置时发生冲突了,那么我们可以将冲突的部分排除掉,即告诉SpringBoot,某个类不用帮我自动配置了,这里我们将Druid的关于数据源的配置排除掉。
因为hcHousingResourcesBaseRepository(JPA接口) 这个bean的名字在容器中已经有了 所以我的想法是先排除
第一种排除方法
在配置类中排除自动配置的 并在配置文件中配置 自动配置类bean名字可以覆盖
@SpringBootApplication(exclude={HcHousingResourcesRepository.class})
spring:
datasource:
main:
allow-bean-definition-overriding: true
第二种方法是排除自定义的
@ComponentScan(excludeFilters= {@ComponentScan.Filter(type= FilterType.ANNOTATION, value= {HcHousingResourcesRepository.class})})
但是都没有用 放到tomcat下还是会报错
最终解决方案:
@Component(value = “HcHousingRepository”)
spring:
datasource:
main:
allow-bean-definition-overriding: true
自定义一下接口的名字 然后将之前的bean名称覆盖 启动的时候就不会冲突 从而解决bean启动因为名称冲突的问题