In a scenario where there are multiple beans of the same type, how can one specify which bean should be Autowired?
- Use the @Qualifier annotation with the desired bean's name.
- Use the @Autowired annotation with the desired bean's variable name.
- Use the @Inject annotation with the desired bean's ID.
- Use the @Resource annotation with the desired bean's name.
When there are multiple beans of the same type, you can specify which bean should be autowired using the @Qualifier annotation with the desired bean's name. This helps Spring resolve the ambiguity. The other options, while related to dependency injection, do not directly address the issue of selecting a specific bean from multiple candidates.
Loading...
Related Quiz
- How can you handle exceptions globally across multiple controllers in a Spring Boot application?
- In Spring Boot's project structure, where should the application properties file be placed?
- In Spring Boot, the _____ interface is used to represent a reactive stream that emits multiple items.
- How can you handle different HTTP methods in a single method in a Spring Boot controller?
- How can you create a shared bean that is not a singleton in Spring Boot?