Explicit error message for bean name clash with containing configuration class

Issue: SPR-15775
This commit is contained in:
Juergen Hoeller
2017-07-18 00:54:49 +02:00
parent 12114a9d4c
commit bca5a36216
3 changed files with 41 additions and 0 deletions

View File

@@ -198,6 +198,11 @@ class ConfigurationClassBeanDefinitionReader {
// Has this effectively been overridden before (e.g. via XML)?
if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
if (beanName.equals(beanMethod.getConfigurationClass().getBeanName())) {
throw new BeanDefinitionStoreException(beanMethod.getConfigurationClass().getResource().getDescription(),
beanName, "Bean name derived from @Bean method '" + beanMethod.getMetadata().getMethodName() +
"' clashes with bean name for containing configuration class; please make those names unique!");
}
return;
}