springboot 项目启动报注册重复, A bean with that name has already been defined and overridin

springboot 启动时由于多次注册了同一个bean,导致报错: A bean with that name has already been defined and overridin

可能产生的原因:
0、启动类application都是自动扫描本包及其以下的包。就是application主类
1、@MapperScan("mapper的位置"),这里扫包,扫了一次加入bean中。
2、其他方式又加载注入这个同名的bean。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-23 10:22:50.810  INFO [my-server-search,,,] 33172 --- [           main] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2020-04-23 10:22:50.833  INFO [my-server-search,,,] 33172 --- [           main] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient
2020-04-23 10:22:50.837 ERROR [my-server-search,,,] 33172 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'my-server-cms.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

 

在application.yml中加上如下配置问题解决

spring:
 main:
    allow-bean-definition-overriding: true    #当遇到同样名字的时候,是否允许覆盖注册不配置会报错 

 

posted on 2020-04-23 10:28  陈惟鲜的博客  阅读(7886)  评论(0编辑  收藏  举报

导航