Improving test coverage of determinePrimaryCandidate
Added tests checking the behaviour of autowiring by type when the @Primary annotation is present on the class. Fixed also some inconsistencies in the code.
This commit is contained in:
@@ -1045,11 +1045,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
if (primaryBeanName != null) {
|
||||
boolean candidateLocal = containsBeanDefinition(candidateBeanName);
|
||||
boolean primaryLocal = containsBeanDefinition(primaryBeanName);
|
||||
if (candidateLocal == primaryLocal) {
|
||||
if (candidateLocal && primaryLocal) {
|
||||
throw new NoUniqueBeanDefinitionException(descriptor.getDependencyType(), candidateBeans.size(),
|
||||
"more than one 'primary' bean found among candidates: " + candidateBeans.keySet());
|
||||
}
|
||||
else if (candidateLocal && !primaryLocal) {
|
||||
else if (candidateLocal) {
|
||||
primaryBeanName = candidateBeanName;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user