【发布时间】:2019-04-08 00:19:59
【问题描述】:
我已经定义了ConfigServicePropertySourceLocator bean,如下所示
@Primary
@Bean
public ConfigServicePropertySourceLocator configServicePropertySource(
ConfigClientProperties configClientProperties) {
ConfigServicePropertySourceLocator sourceLocator = new ConfigServicePropertySourceLocator(
configClientProperties);
sourceLocator.setRestTemplate(clientOnlyRestTemplate());
return sourceLocator;
}
但我得到以下异常(这是它在 docker 中的打印方式)虽然我的 bean 被标记为 @Primary
WARN 1 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.support.BeanDefinitionOverrideException:
Invalid bean definition with name 'configServicePropertySource' defined in de.ig.client.security.configuration.ConfigClientSecurityConfiguration:
Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3;
dependencyCheck=0; autowireCandidate=true; primary=true; factoryBeanName=configClientSecurityConfiguration;
factoryMethodName=configServicePropertySource; initMethodName=null; destroyMethodName=(inferred);
defined in de.ig.client.security.configuration.ConfigClientSecurityConfiguration] for bean 'configServicePropertySource':
There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0;
autowireCandidate=true; primary=false; factoryBeanName=configServiceBootstrapConfiguration;
factoryMethodName=configServicePropertySource; initMethodName=null; destroyMethodName=(inferred);
defined in org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration] bound.
【问题讨论】:
-
你能查一下this
-
@buræquete 链接提到类加载问题。这是bean覆盖问题。更糟糕的是,即使使用 Primary 注释,它也会抛出异常。很奇怪。
-
看起来很奇怪.. 但您可以添加@Order(-1) 并删除@Primary...
-
@JonathanJohx 下单后出现同样的异常。
标签: spring spring-boot spring-oauth2 spring-config