工程中引入其他工程的包,由于两个工程中有重名的两个bean,导致在启动时提示如下错误:

bean名称相同冲突Annotation-specified bean name 'xx' for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]

根据bean名称在ide中查找,找到这两个重名的类,可以看到由于这两个类使用@Service标注,此时如果不使用命名,那么Spring会在扫描时,将类名首字母小写作为key,放到一个全局Map中维护。此时,会出现两个键相同的Service,由于Spring不使用覆盖的方式处理具有相同键的不同全类名,所以扫描时提示冲突。

bean名称相同冲突Annotation-specified bean name 'xx' for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]

解决方法:保持容器中bean的名称不重复,对其中的一个bean进行自定义命名。

bean名称相同冲突Annotation-specified bean name 'xx' for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]

 

相关文章:

  • 2021-05-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2022-01-24
猜你喜欢
  • 2021-08-22
  • 2021-11-03
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案