Skip to content

Commit d7e0eed

Browse files
committed
Clarify getBeanProvider(ResolvableType) semantics for unresolved generics
Closes gh-27727
1 parent 7c834d9 commit d7e0eed

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public interface BeanFactory {
214214
/**
215215
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
216216
* of instances, including availability and uniqueness options.
217+
* <p>For matching a generic type, consider {@link #getBeanProvider(ResolvableType)}.
217218
* @param requiredType type the bean must match; can be an interface or superclass
218219
* @return a corresponding provider handle
219220
* @since 5.1
@@ -223,13 +224,20 @@ public interface BeanFactory {
223224

224225
/**
225226
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
226-
* of instances, including availability and uniqueness options.
227-
* @param requiredType type the bean must match; can be a generic type declaration.
228-
* Note that collection types are not supported here, in contrast to reflective
227+
* of instances, including availability and uniqueness options. This variant allows
228+
* for specifying a generic type to match, similar to reflective injection points
229+
* with generic type declarations in method/constructor parameters.
230+
* <p>Note that collections of beans are not supported here, in contrast to reflective
229231
* injection points. For programmatically retrieving a list of beans matching a
230232
* specific type, specify the actual bean type as an argument here and subsequently
231233
* use {@link ObjectProvider#orderedStream()} or its lazy streaming/iteration options.
234+
* <p>Also, generics matching is strict here, as per the Java assignment rules.
235+
* For lenient fallback matching with unchecked semantics (similar to the ´unchecked´
236+
* Java compiler warning), consider calling {@link #getBeanProvider(Class)} with the
237+
* raw type as a second step if no full generic match is
238+
* {@link ObjectProvider#getIfAvailable() available} with this variant.
232239
* @return a corresponding provider handle
240+
* @param requiredType type the bean must match; can be a generic type declaration
233241
* @since 5.1
234242
* @see ObjectProvider#iterator()
235243
* @see ObjectProvider#stream()

0 commit comments

Comments
 (0)