diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java index 492d224a9cb..d62c3ee6d3c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java @@ -46,6 +46,21 @@ import org.springframework.lang.Nullable; * Alternatively, you may implement the specific methods that your callers expect, * for example, just {@link #getObject()} or {@link #getIfAvailable()}. * + *
Note that {@link #getObject()} never returns {@code null} - it will throw a + * {@link NoSuchBeanDefinitionException} instead -, whereas {@link #getIfAvailable()} + * will return {@code null} if no matching bean is present at all. However, both + * methods will throw a {@link NoUniqueBeanDefinitionException} if more than one + * matching bean is found without a clear unique winner (see below). Last but not + * least, {@link #getIfUnique()} will return {@code null} both when no matching bean + * is found and when more than one matching bean is found without a unique winner. + * + *
Uniqueness is generally up to the container's candidate resolution algorithm
+ * but always honors the "primary" flag (with only one of the candidate beans marked
+ * as primary) and the "fallback" flag (with only one of the candidate beans not
+ * marked as fallback). The default-candidate flag is consistently taken into
+ * account as well, even for non-annotation-based injection points, with a single
+ * default candidate winning in case of no clear primary/fallback indication.
+ *
* @author Juergen Hoeller
* @since 4.3
* @param