@@ -66,10 +66,40 @@ public AutowireCandidateResolver cloneIfNecessary() {
6666 * @see org.springframework.beans.factory.config.BeanDefinition#isAutowireCandidate()
6767 * @see AbstractBeanDefinition#isDefaultCandidate()
6868 */
69- @ SuppressWarnings ("unchecked" )
7069 public static <T > Map <String , T > resolveAutowireCandidates (ConfigurableListableBeanFactory lbf , Class <T > type ) {
70+ return resolveAutowireCandidates (lbf , type , true , true );
71+ }
72+
73+ /**
74+ * Resolve a map of all beans of the given type, also picking up beans defined in
75+ * ancestor bean factories, with the specific condition that each bean actually
76+ * has autowire candidate status. This matches simple injection point resolution
77+ * as implemented by this {@link AutowireCandidateResolver} strategy, including
78+ * beans which are not marked as default candidates but excluding beans which
79+ * are not even marked as autowire candidates.
80+ * @param lbf the bean factory
81+ * @param type the type of bean to match
82+ * @param includeNonSingletons whether to include prototype or scoped beans too
83+ * or just singletons (also applies to FactoryBeans)
84+ * @param allowEagerInit whether to initialize <i>lazy-init singletons</i> and
85+ * <i>objects created by FactoryBeans</i> (or by factory methods with a
86+ * "factory-bean" reference) for the type check. Note that FactoryBeans need to be
87+ * eagerly initialized to determine their type: So be aware that passing in "true"
88+ * for this flag will initialize FactoryBeans and "factory-bean" references.
89+ * @return the Map of matching bean instances, or an empty Map if none
90+ * @throws BeansException if a bean could not be created
91+ * @since 6.2.5
92+ * @see BeanFactoryUtils#beansOfTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
93+ * @see org.springframework.beans.factory.config.BeanDefinition#isAutowireCandidate()
94+ * @see AbstractBeanDefinition#isDefaultCandidate()
95+ */
96+ @ SuppressWarnings ("unchecked" )
97+ public static <T > Map <String , T > resolveAutowireCandidates (ConfigurableListableBeanFactory lbf , Class <T > type ,
98+ boolean includeNonSingletons , boolean allowEagerInit ) {
99+
71100 Map <String , T > candidates = new LinkedHashMap <>();
72- for (String beanName : BeanFactoryUtils .beanNamesForTypeIncludingAncestors (lbf , type )) {
101+ for (String beanName : BeanFactoryUtils .beanNamesForTypeIncludingAncestors (lbf , type ,
102+ includeNonSingletons , allowEagerInit )) {
73103 if (AutowireUtils .isAutowireCandidate (lbf , beanName )) {
74104 Object beanInstance = lbf .getBean (beanName );
75105 if (!(beanInstance instanceof NullBean )) {
0 commit comments