Imagine you are resolving a dependency injection issue in a project. What approach and considerations would you take to resolve ambiguity in autowiring of beans and ensure that the correct bean is injected?
- Use the @Primary annotation to designate a primary bean for autowiring and resolve ambiguity.
- Use the @Qualifier annotation to specify the bean name or qualifier to resolve ambiguity.
- Increase the scope of the bean to singleton to ensure there's only one instance available for autowiring.
- Use the @Autowired annotation without qualifiers and let Spring choose the best candidate based on the context.
To resolve ambiguity in autowiring of beans, you can use the @Qualifier annotation to specify the bean name or qualifier explicitly. This approach ensures that the correct bean is injected. The @Primary annotation designates a primary bean, which can also help resolve ambiguity. The other options don't directly address ambiguity resolution.
Loading...
Related Quiz
- In Spring Boot, to create a condition based on the presence or absence of a specific bean, the _____ annotation can be used.
- How can you implement token enhancement to include custom claims in an OAuth2 JWT token generated by a Spring Boot application?
- When creating a custom query in Spring Data JPA, the _____ annotation is used to modify the underlying query execution.
- What is the primary role of the UserDetailsService in Spring Security?
- You are tasked with optimizing the request handling process in a large Spring Boot application, considering factors like request routing, data binding, and response generation. How would you approach this optimization?