Member-only story
Spring Framework 6.2 — Fallback Annotation
This story explores the usage of the Fallback annotation introduced in Spring Framework 6.2.
· Prerequisites
· Overview
· Example
∘ @Primary Annotation
∘ @Fallback Annotation
∘ Fine-tuning Annotation-based Autowiring with Qualifiers
· Conclusion
· References
Prerequisites
This is the list of all the prerequisites:
- Spring Boot 3.4+
- Java 17 or later
Overview
Spring 6.2 added support for fallback beans. A fallback bean is used if no bean of that type has been provided. It is a substitute for the @Primary annotation.
If all beans but one among multiple matching candidates are marked as a fallback, the remaining bean will be selected.
Example
@Primary Annotation
The @Primary
annotation in Spring is used to indicate that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency.