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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *