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配置中心中.