Document @Fallback alongside Primary in the reference docs and @Bean Javadoc

Closes gh-36439
This commit is contained in:
Sam Brannen
2026-03-10 17:09:13 +01:00
parent 3b8efbe5a6
commit 27686dc2e2
6 changed files with 27 additions and 19 deletions
@@ -57,11 +57,11 @@ import org.springframework.core.annotation.AliasFor;
* return obj;
* }</pre>
*
* <h3>Profile, Scope, Lazy, DependsOn, Primary, Order</h3>
* <h3>Profile, Scope, Lazy, DependsOn, Primary, Fallback, Order</h3>
*
* <p>Note that the {@code @Bean} annotation does not provide attributes for profile,
* scope, lazy, depends-on or primary. Rather, it should be used in conjunction with
* {@link Scope @Scope}, {@link Lazy @Lazy}, {@link DependsOn @DependsOn} and
* scope, lazy, depends-on, or primary. Rather, it should be used in conjunction with
* {@link Scope @Scope}, {@link Lazy @Lazy}, {@link DependsOn @DependsOn}, and
* {@link Primary @Primary} annotations to declare those semantics. For example:
*
* <pre class="code">
@@ -82,6 +82,9 @@ import org.springframework.core.annotation.AliasFor;
* through direct references, which is typically helpful for singleton startup.
* {@code @Primary} is a mechanism to resolve ambiguity at the injection point level
* if a single target component needs to be injected but several beans match by type.
* {@code @Fallback} marks a bean as a fallback candidate in such scenarios; if all
* beans but one among multiple matching candidates are marked as fallback, the
* remaining bean will be selected.
*
* <p>Additionally, {@code @Bean} methods may also declare qualifier annotations
* and {@link org.springframework.core.annotation.Order @Order} values, to be
@@ -97,8 +100,8 @@ import org.springframework.core.annotation.AliasFor;
* orthogonal concern determined by dependency relationships and {@code @DependsOn}
* declarations as mentioned above. Also, {@link jakarta.annotation.Priority} is not
* available at this level since it cannot be declared on methods; its semantics can
* be modeled through {@code @Order} values in combination with {@code @Primary} on
* a single bean per type.
* be modeled through {@code @Order} values in combination with {@code @Primary} or
* {@code @Fallback} on a single bean per type.
*
* <h3>{@code @Bean} Methods in {@code @Configuration} Classes</h3>
*
@@ -230,6 +233,7 @@ import org.springframework.core.annotation.AliasFor;
* @see DependsOn
* @see Lazy
* @see Primary
* @see Fallback
* @see org.springframework.stereotype.Component
* @see org.springframework.beans.factory.annotation.Autowired
* @see org.springframework.beans.factory.annotation.Value