|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.beans.factory.annotation;
|
18 | 18 |
|
19 | 19 | import java.lang.reflect.Method;
|
20 |
| -import java.util.Map; |
21 | 20 |
|
22 | 21 | import org.springframework.beans.factory.BeanFactory;
|
23 | 22 | import org.springframework.beans.factory.BeanFactoryUtils;
|
@@ -77,20 +76,19 @@ else if (beanFactory.containsBean(qualifier)) {
|
77 | 76 | * @throws NoSuchBeanDefinitionException if no matching bean of type {@code T} found
|
78 | 77 | */
|
79 | 78 | private static <T> T qualifiedBeanOfType(ConfigurableListableBeanFactory bf, Class<T> beanType, String qualifier) {
|
80 |
| - Map<String, T> candidateBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, beanType); |
81 |
| - T matchingBean = null; |
82 |
| - for (Map.Entry<String, T> entry : candidateBeans.entrySet()) { |
83 |
| - String beanName = entry.getKey(); |
| 79 | + String[] candidateBeans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(bf, beanType); |
| 80 | + String matchingBean = null; |
| 81 | + for (String beanName : candidateBeans) { |
84 | 82 | if (isQualifierMatch(qualifier, beanName, bf)) {
|
85 | 83 | if (matchingBean != null) {
|
86 | 84 | throw new NoSuchBeanDefinitionException(qualifier, "No unique " + beanType.getSimpleName() +
|
87 | 85 | " bean found for qualifier '" + qualifier + "'");
|
88 | 86 | }
|
89 |
| - matchingBean = entry.getValue(); |
| 87 | + matchingBean = beanName; |
90 | 88 | }
|
91 | 89 | }
|
92 | 90 | if (matchingBean != null) {
|
93 |
| - return matchingBean; |
| 91 | + return bf.getBean(matchingBean, beanType); |
94 | 92 | }
|
95 | 93 | else if (bf.containsBean(qualifier)) {
|
96 | 94 | // Fallback: target bean at least found by bean name - probably a manually registered singleton.
|
|
0 commit comments