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

Leave a comment

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