名称为 'configServicePropertySource' 的 Bean 定义无效



我定义了类似于以下的ConfigServicePropertySourceLocatorbean

@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.

通过设置解决

spring.main.allow-bean-definition-overriding

2.1版启动后的新功能

相关内容

  • 没有找到相关文章

最新更新