Only register DynamicPropertySourceBeanInitializer if necessary
This commit makes sure to check first if DynamicPropertySourceBeanInitializer has been registered before trying to register it. When running with AOT optimizations, the bean definition has been contributed so there is no need to register it again when the context customizer runs. Closes gh-33272
This commit is contained in:
@@ -78,10 +78,12 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer {
|
||||
new DefaultDynamicPropertyRegistry(environment, this.methods.isEmpty());
|
||||
beanFactory.registerSingleton(DYNAMIC_PROPERTY_REGISTRY_BEAN_NAME, dynamicPropertyRegistry);
|
||||
|
||||
BeanDefinition beanDefinition = new RootBeanDefinition(DynamicPropertySourceBeanInitializer.class);
|
||||
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
beanDefinitionRegistry.registerBeanDefinition(
|
||||
DYNAMIC_PROPERTY_SOURCE_BEAN_INITIALIZER_BEAN_NAME, beanDefinition);
|
||||
if (!beanDefinitionRegistry.containsBeanDefinition(DYNAMIC_PROPERTY_SOURCE_BEAN_INITIALIZER_BEAN_NAME)) {
|
||||
BeanDefinition beanDefinition = new RootBeanDefinition(DynamicPropertySourceBeanInitializer.class);
|
||||
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
beanDefinitionRegistry.registerBeanDefinition(
|
||||
DYNAMIC_PROPERTY_SOURCE_BEAN_INITIALIZER_BEAN_NAME, beanDefinition);
|
||||
}
|
||||
|
||||
if (!this.methods.isEmpty()) {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
|
||||
Reference in New Issue
Block a user