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    #當遇到同樣名字的時候,是否允許覆蓋注冊不配置會報錯 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM