远程配置无效 spring.main.allow-bean-definition-overriding=true
例外情况:
org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'cms.FeignClientSpecification' defined in null: Cannot register bean definition [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'cms.FeignClientSpecification': There is already [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound. at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:891) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE] at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerClientConfiguration(FeignClientsRegistrar.java:389) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClients(FeignClientsRegistrar.java:216) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerBeanDefinitions(FeignClientsRegistrar.java:144) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:364) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader$$Lambda$158/5142724.accept(Unknown Source) ~[?:?] at java.util.LinkedHashMap.forEach(LinkedHashMap.java:676) ~[?:1.8.0_45]
原提问者GitHub用户lujiafa
这不是一个bug,远程属性不会覆盖本地spring.main**属性,因为绑定allowBeanDefinitionOverride的prepareEnvironment方法总是在pull远程配置上的prepareContext方法之前执行。您可以直接在bootstrap.properties中进行设
原回答者GitHub用户echooymxq
2023-06-11 11:25:32