tomcat启动spring项目,报具有该名称的xxxbean已经在xxx定义,覆盖被禁止

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启动因为名称冲突的问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值