spring.main.allow-bean-definition-overriding: true 改配置不能放到nacos配置中心中

1.展示一下異常(nacos中已經(jīng)配置spring.main.allow-bean-definition-overriding=true依然報(bào)錯(cuò))

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-03-07 16:28:45.687 ERROR 1853 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

The bean 'team-chat.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.解決方案:

spring.main.allow-bean-definition-overriding=true放置到配置nacos的配置文件中

舉例: 項(xiàng)目的環(huán)境有(本地,開(kāi)發(fā),測(cè)試,生產(chǎn))

分別是: bootstrap-local.yml、bootstrap-dev.yml、bootstrap-test.yml、bootstrap-prod.yml

bootstrap-dev.yml的nacos配置如下:

spring:
  application:
    name: team-talk #服務(wù)名稱(chēng)
  main:
    allow-bean-definition-overriding: true #當(dāng)遇到同樣名字的時(shí)候,是否允許覆蓋注冊(cè)
  cloud:
    nacos:
      discovery:
        server-addr:***.mse.aliyuncs.com:8848,6443,9848
      config: # 拉取配置中心需要改成application配置文件,優(yōu)先加載
        file-extension: yaml # 配置文件格式
        group: TEAM_GROUP
        server-addr: ***.mse.aliyuncs.com:8848,6443,9848
        enable-remote-sync-config: true

測(cè)試環(huán)境和生產(chǎn)環(huán)境都是同樣的配置,spring.main.allow-bean-definition-overriding=true不放置在nacos配置中心中.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容