What is the purpose of the @Primary annotation in Spring?
- Define a bean's name
- Define a bean's scope
- Mark a bean as deprecated
- Specify the primary bean
The purpose of the @Primary annotation in Spring is to specify the primary bean when multiple beans of the same type exist. When multiple beans qualify as dependencies for injection, the one marked with @Primary is the one that Spring will choose by default. This is useful in scenarios where you have multiple implementations of an interface or class, and one should be considered the primary choice.
Loading...
Related Quiz
- You are tasked with creating a comprehensive test suite for a Spring Boot application. How would you approach testing the various layers and components, ensuring optimal coverage and efficiency?
- What is the primary file used to define properties in Spring Boot?
- Imagine you are developing a Spring Boot application where you need to validate incoming request payloads against a complex business rule. How would you approach implementing such a validation?
- Which component in Spring Security is responsible for evaluating method security annotations like @Secured and @PreAuthorize?
- When configuring OAuth2 Resource Server in Spring Boot, the _____ property is used to specify the location of the public key for verifying JWT signatures.