1.报错信息
*************************** APPLICATION FAILED TO START ***************************
Description: The bean 'algorithmServiceFeign.FeignClientSpecification' could not be registered.
A bean with that name has already been defined and overriding is disabled.
Action: Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
2.问题分析
这个报错显示你的bean A已经被注册过一次了,现在还想再注册一次但是该项目没有加上可覆盖的选项,因此出现错误:IOC容器中的bean只能是单例的,不能出现两个同样名称的bean,否则就会出现冲突。
一般出现这种情况有以下这些原因:
1.bean的名称重复(粗心导致),这样的话就直接修改注册bean时的名字即可。
2.模块B依赖了模块A(因为模块B需要使用到beanA,但是在不同模块,因此添加了模块A的依赖),因此在加载模块A和模块B时,对于bean A就会注册两次,因此就会出现重复bean报错。解决方案就是取消模块B对模块A的依赖,将模块A中的bean A移动到公共模块中,然后模块B和模块A共同依赖公共模块C,即可解决该报错。
3.此外,也可以通过设置spring.main.allow-bean-definition-overriding=true来允许bean覆盖,但这通常不推荐作为首选解决方案。
353

被折叠的 条评论
为什么被折叠?



