Skip to content

Commit e90a2da

Browse files
committed
Clarify defensive impact of allowEagerInit flag for type matching
Closes gh-33740
1 parent d48f388 commit e90a2da

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

Diff for: spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java

+33-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -92,9 +92,13 @@ public interface ListableBeanFactory extends BeanFactory {
9292
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
9393
* of instances, including availability and uniqueness options.
9494
* @param requiredType type the bean must match; can be an interface or superclass
95-
* @param allowEagerInit whether stream-based access may initialize <i>lazy-init
96-
* singletons</i> and <i>objects created by FactoryBeans</i> (or by factory methods
97-
* with a "factory-bean" reference) for the type check
95+
* @param allowEagerInit whether stream access may introspect <i>lazy-init singletons</i>
96+
* and <i>objects created by FactoryBeans</i> - or by factory methods with a
97+
* "factory-bean" reference - for the type check. Note that FactoryBeans need to be
98+
* eagerly initialized to determine their type: So be aware that passing in "true"
99+
* for this flag will initialize FactoryBeans and "factory-bean" references. Only
100+
* actually necessary initialization for type checking purposes will be performed;
101+
* constructor and method invocations will still be avoided as far as possible.
98102
* @return a corresponding provider handle
99103
* @since 5.3
100104
* @see #getBeanProvider(ResolvableType, boolean)
@@ -112,9 +116,13 @@ public interface ListableBeanFactory extends BeanFactory {
112116
* injection points. For programmatically retrieving a list of beans matching a
113117
* specific type, specify the actual bean type as an argument here and subsequently
114118
* use {@link ObjectProvider#orderedStream()} or its lazy streaming/iteration options.
115-
* @param allowEagerInit whether stream-based access may initialize <i>lazy-init
116-
* singletons</i> and <i>objects created by FactoryBeans</i> (or by factory methods
117-
* with a "factory-bean" reference) for the type check
119+
* @param allowEagerInit whether stream access may introspect <i>lazy-init singletons</i>
120+
* and <i>objects created by FactoryBeans</i> - or by factory methods with a
121+
* "factory-bean" reference - for the type check. Note that FactoryBeans need to be
122+
* eagerly initialized to determine their type: So be aware that passing in "true"
123+
* for this flag will initialize FactoryBeans and "factory-bean" references. Only
124+
* actually necessary initialization for type checking purposes will be performed;
125+
* constructor and method invocations will still be avoided as far as possible.
118126
* @return a corresponding provider handle
119127
* @since 5.3
120128
* @see #getBeanProvider(ResolvableType)
@@ -175,11 +183,13 @@ public interface ListableBeanFactory extends BeanFactory {
175183
* @param type the generically typed class or interface to match
176184
* @param includeNonSingletons whether to include prototype or scoped beans too
177185
* or just singletons (also applies to FactoryBeans)
178-
* @param allowEagerInit whether to initialize <i>lazy-init singletons</i> and
179-
* <i>objects created by FactoryBeans</i> (or by factory methods with a
180-
* "factory-bean" reference) for the type check. Note that FactoryBeans need to be
186+
* @param allowEagerInit whether to introspect <i>lazy-init singletons</i>
187+
* and <i>objects created by FactoryBeans</i> - or by factory methods with a
188+
* "factory-bean" reference - for the type check. Note that FactoryBeans need to be
181189
* eagerly initialized to determine their type: So be aware that passing in "true"
182-
* for this flag will initialize FactoryBeans and "factory-bean" references.
190+
* for this flag will initialize FactoryBeans and "factory-bean" references. Only
191+
* actually necessary initialization for type checking purposes will be performed;
192+
* constructor and method invocations will still be avoided as far as possible.
183193
* @return the names of beans (or objects created by FactoryBeans) matching
184194
* the given object type (including subclasses), or an empty array if none
185195
* @since 5.2
@@ -236,11 +246,13 @@ public interface ListableBeanFactory extends BeanFactory {
236246
* @param type the class or interface to match, or {@code null} for all bean names
237247
* @param includeNonSingletons whether to include prototype or scoped beans too
238248
* or just singletons (also applies to FactoryBeans)
239-
* @param allowEagerInit whether to initialize <i>lazy-init singletons</i> and
240-
* <i>objects created by FactoryBeans</i> (or by factory methods with a
241-
* "factory-bean" reference) for the type check. Note that FactoryBeans need to be
249+
* @param allowEagerInit whether to introspect <i>lazy-init singletons</i>
250+
* and <i>objects created by FactoryBeans</i> - or by factory methods with a
251+
* "factory-bean" reference - for the type check. Note that FactoryBeans need to be
242252
* eagerly initialized to determine their type: So be aware that passing in "true"
243-
* for this flag will initialize FactoryBeans and "factory-bean" references.
253+
* for this flag will initialize FactoryBeans and "factory-bean" references. Only
254+
* actually necessary initialization for type checking purposes will be performed;
255+
* constructor and method invocations will still be avoided as far as possible.
244256
* @return the names of beans (or objects created by FactoryBeans) matching
245257
* the given object type (including subclasses), or an empty array if none
246258
* @see FactoryBean#getObjectType
@@ -300,11 +312,13 @@ public interface ListableBeanFactory extends BeanFactory {
300312
* @param type the class or interface to match, or {@code null} for all concrete beans
301313
* @param includeNonSingletons whether to include prototype or scoped beans too
302314
* or just singletons (also applies to FactoryBeans)
303-
* @param allowEagerInit whether to initialize <i>lazy-init singletons</i> and
304-
* <i>objects created by FactoryBeans</i> (or by factory methods with a
305-
* "factory-bean" reference) for the type check. Note that FactoryBeans need to be
315+
* @param allowEagerInit whether to introspect <i>lazy-init singletons</i>
316+
* and <i>objects created by FactoryBeans</i> - or by factory methods with a
317+
* "factory-bean" reference - for the type check. Note that FactoryBeans need to be
306318
* eagerly initialized to determine their type: So be aware that passing in "true"
307-
* for this flag will initialize FactoryBeans and "factory-bean" references.
319+
* for this flag will initialize FactoryBeans and "factory-bean" references. Only
320+
* actually necessary initialization for type checking purposes will be performed;
321+
* constructor and method invocations will still be avoided as far as possible.
308322
* @return a Map with the matching beans, containing the bean names as
309323
* keys and the corresponding bean instances as values
310324
* @throws BeansException if a bean could not be created

0 commit comments

Comments
 (0)