Skip to content

Commit 4bd280b

Browse files
committed
Explain availability and uniqueness (including primary/fallback/default) in javadoc
Closes gh-34447
1 parent 5877a38 commit 4bd280b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@
4646
* Alternatively, you may implement the specific methods that your callers expect,
4747
* for example, just {@link #getObject()} or {@link #getIfAvailable()}.
4848
*
49+
* <p>Note that {@link #getObject()} never returns {@code null} - it will throw a
50+
* {@link NoSuchBeanDefinitionException} instead -, whereas {@link #getIfAvailable()}
51+
* will return {@code null} if no matching bean is present at all. However, both
52+
* methods will throw a {@link NoUniqueBeanDefinitionException} if more than one
53+
* matching bean is found without a clear unique winner (see below). Last but not
54+
* least, {@link #getIfUnique()} will return {@code null} both when no matching bean
55+
* is found and when more than one matching bean is found without a unique winner.
56+
*
57+
* <p>Uniqueness is generally up to the container's candidate resolution algorithm
58+
* but always honors the "primary" flag (with only one of the candidate beans marked
59+
* as primary) and the "fallback" flag (with only one of the candidate beans not
60+
* marked as fallback). The default-candidate flag is consistently taken into
61+
* account as well, even for non-annotation-based injection points, with a single
62+
* default candidate winning in case of no clear primary/fallback indication.
63+
*
4964
* @author Juergen Hoeller
5065
* @since 4.3
5166
* @param <T> the object type
@@ -188,7 +203,7 @@ default T getIfUnique(Supplier<T> defaultSupplier) throws BeansException {
188203
* if unique (not called otherwise)
189204
* @throws BeansException in case of creation errors
190205
* @since 5.0
191-
* @see #getIfAvailable()
206+
* @see #getIfUnique()
192207
*/
193208
default void ifUnique(Consumer<T> dependencyConsumer) throws BeansException {
194209
T dependency = getIfUnique();

0 commit comments

Comments
 (0)