|
|
|
@ -1996,12 +1996,15 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto |
|
|
|
* @param requiredType the target dependency type to match against |
|
|
|
* @param requiredType the target dependency type to match against |
|
|
|
* @return the name of the candidate with the highest priority, |
|
|
|
* @return the name of the candidate with the highest priority, |
|
|
|
* or {@code null} if none found |
|
|
|
* or {@code null} if none found |
|
|
|
|
|
|
|
* @throws NoUniqueBeanDefinitionException if multiple beans are detected with |
|
|
|
|
|
|
|
* the same highest priority value |
|
|
|
* @see #getPriority(Object) |
|
|
|
* @see #getPriority(Object) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
protected String determineHighestPriorityCandidate(Map<String, Object> candidates, Class<?> requiredType) { |
|
|
|
protected String determineHighestPriorityCandidate(Map<String, Object> candidates, Class<?> requiredType) { |
|
|
|
String highestPriorityBeanName = null; |
|
|
|
String highestPriorityBeanName = null; |
|
|
|
Integer highestPriority = null; |
|
|
|
Integer highestPriority = null; |
|
|
|
|
|
|
|
boolean highestPriorityConflictDetected = false; |
|
|
|
for (Map.Entry<String, Object> entry : candidates.entrySet()) { |
|
|
|
for (Map.Entry<String, Object> entry : candidates.entrySet()) { |
|
|
|
String candidateBeanName = entry.getKey(); |
|
|
|
String candidateBeanName = entry.getKey(); |
|
|
|
Object beanInstance = entry.getValue(); |
|
|
|
Object beanInstance = entry.getValue(); |
|
|
|
@ -2010,13 +2013,12 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto |
|
|
|
if (candidatePriority != null) { |
|
|
|
if (candidatePriority != null) { |
|
|
|
if (highestPriority != null) { |
|
|
|
if (highestPriority != null) { |
|
|
|
if (candidatePriority.equals(highestPriority)) { |
|
|
|
if (candidatePriority.equals(highestPriority)) { |
|
|
|
throw new NoUniqueBeanDefinitionException(requiredType, candidates.size(), |
|
|
|
highestPriorityConflictDetected = true; |
|
|
|
"Multiple beans found with the same priority ('" + highestPriority + |
|
|
|
|
|
|
|
"') among candidates: " + candidates.keySet()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if (candidatePriority < highestPriority) { |
|
|
|
else if (candidatePriority < highestPriority) { |
|
|
|
highestPriorityBeanName = candidateBeanName; |
|
|
|
highestPriorityBeanName = candidateBeanName; |
|
|
|
highestPriority = candidatePriority; |
|
|
|
highestPriority = candidatePriority; |
|
|
|
|
|
|
|
highestPriorityConflictDetected = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
@ -2026,6 +2028,13 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (highestPriorityConflictDetected) { |
|
|
|
|
|
|
|
throw new NoUniqueBeanDefinitionException(requiredType, candidates.size(), |
|
|
|
|
|
|
|
"Multiple beans found with the same highest priority (" + highestPriority + |
|
|
|
|
|
|
|
") among candidates: " + candidates.keySet()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
return highestPriorityBeanName; |
|
|
|
return highestPriorityBeanName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|