BeanFactory prefers local primary bean to primary bean in parent factory (SPR-5871)

This commit is contained in:
Juergen Hoeller
2009-09-08 23:01:26 +00:00
parent ee1c68ead4
commit 634d4b4d4c
2 changed files with 34 additions and 9 deletions

View File

@@ -808,10 +808,19 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
Object beanInstance = entry.getValue();
if (isPrimary(candidateBeanName, beanInstance)) {
if (primaryBeanName != null) {
throw new NoSuchBeanDefinitionException(descriptor.getDependencyType(),
"more than one 'primary' bean found among candidates: " + candidateBeans.keySet());
boolean candidateLocal = containsBeanDefinition(candidateBeanName);
boolean primaryLocal = containsBeanDefinition(primaryBeanName);
if (candidateLocal == primaryLocal) {
throw new NoSuchBeanDefinitionException(descriptor.getDependencyType(),
"more than one 'primary' bean found among candidates: " + candidateBeans.keySet());
}
else if (candidateLocal && !primaryLocal) {
primaryBeanName = candidateBeanName;
}
}
else {
primaryBeanName = candidateBeanName;
}
primaryBeanName = candidateBeanName;
}
if (primaryBeanName == null &&
(this.resolvableDependencies.values().contains(beanInstance) ||