Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Spring Framework FAQ: Top Questions

49. What are Spring qualifiers and when do you use @Qualifier?

@Qualifier is used alongside @Autowired to specify which bean to inject when multiple candidates of the same type exist.

📥 Example:

@Component("cat")
public class Cat implements Animal {}

@Component("dog")
public class Dog implements Animal {}

@Autowired
@Qualifier("dog")
private Animal animal;

🏆 Expected Output:

Injects the Dog implementation into the Animal field.

🛠️ Use Cases:

  • Resolve bean ambiguity during autowiring.
  • Customize injections for testing or profiling.