Invalid bean definition with name 'configServicePropertySource'

1.7k views Asked by At

I have defined ConfigServicePropertySourceLocator bean like following

@Primary
@Bean
public ConfigServicePropertySourceLocator configServicePropertySource(
        ConfigClientProperties configClientProperties) {
    ConfigServicePropertySourceLocator sourceLocator = new ConfigServicePropertySourceLocator(
            configClientProperties);
    sourceLocator.setRestTemplate(clientOnlyRestTemplate());
    return sourceLocator;
}

but i get the following exception (This is how it is printed in docker) although my bean is marked as @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.
1

There are 1 answers

0
Saurabh Kumar On

Solved it by setting

spring.main.allow-bean-definition-overriding to true

New from boot version 2.1