|
|
|
|
@ -292,6 +292,7 @@ class ConfigurationClassBeanDefinitionReader {
@@ -292,6 +292,7 @@ class ConfigurationClassBeanDefinitionReader {
|
|
|
|
|
this.registry.registerBeanDefinition(beanName, beanDefToRegister); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("NullAway") |
|
|
|
|
protected boolean isOverriddenByExistingDefinition(BeanMethod beanMethod, String beanName) { |
|
|
|
|
if (!this.registry.containsBeanDefinition(beanName)) { |
|
|
|
|
return false; |
|
|
|
|
@ -302,21 +303,23 @@ class ConfigurationClassBeanDefinitionReader {
@@ -302,21 +303,23 @@ class ConfigurationClassBeanDefinitionReader {
|
|
|
|
|
// If the bean method is an overloaded case on the same configuration class,
|
|
|
|
|
// preserve the existing bean definition and mark it as overloaded.
|
|
|
|
|
if (existingBeanDef instanceof ConfigurationClassBeanDefinition ccbd) { |
|
|
|
|
if (ccbd.getMetadata().getClassName().equals(configClass.getMetadata().getClassName())) { |
|
|
|
|
if (ccbd.getFactoryMethodMetadata().getMethodName().equals(beanMethod.getMetadata().getMethodName())) { |
|
|
|
|
ccbd.setNonUniqueFactoryMethodName(ccbd.getFactoryMethodMetadata().getMethodName()); |
|
|
|
|
} |
|
|
|
|
else if (!this.registry.isBeanDefinitionOverridable(beanName)) { |
|
|
|
|
throw new BeanDefinitionOverrideException(beanName, |
|
|
|
|
new ConfigurationClassBeanDefinition(configClass, beanMethod.getMetadata(), beanName), |
|
|
|
|
existingBeanDef, |
|
|
|
|
"@Bean method override with same bean name but different method name: " + existingBeanDef); |
|
|
|
|
} |
|
|
|
|
if (!ccbd.getMetadata().getClassName().equals(configClass.getMetadata().getClassName())) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (ccbd.getFactoryMethodMetadata().getMethodName().equals(beanMethod.getMetadata().getMethodName())) { |
|
|
|
|
ccbd.setNonUniqueFactoryMethodName(ccbd.getFactoryMethodMetadata().getMethodName()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return false; |
|
|
|
|
Map<String, Object> attributes = |
|
|
|
|
configClass.getMetadata().getAnnotationAttributes(Configuration.class.getName()); |
|
|
|
|
if ((attributes != null && (Boolean) attributes.get("enforceUniqueMethods")) || |
|
|
|
|
!this.registry.isBeanDefinitionOverridable(beanName)) { |
|
|
|
|
throw new BeanDefinitionOverrideException(beanName, |
|
|
|
|
new ConfigurationClassBeanDefinition(configClass, beanMethod.getMetadata(), beanName), |
|
|
|
|
existingBeanDef, |
|
|
|
|
"@Bean method override with same bean name but different method name: " + existingBeanDef); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// A bean definition resulting from a component scan can be silently overridden
|
|
|
|
|
|