When multiple beans of the same type exist in a Spring application context, @Autowired alone can't determine which one to inject, so @Qualifier is used alongside it to disambiguate by specifying the exact bean name.
Two PaymentGateway implementations, StripeGateway and PaypalGateway, are both registered as beans; injecting with @Qualifier("stripeGateway") ensures the Stripe implementation is wired in at a specific injection point instead of an ambiguous default.
@Service
public class CheckoutService {
private final PaymentGateway paymentGateway;
public CheckoutService(@Qualifier("stripeGateway") PaymentGateway paymentGateway) {
this.paymentGateway = paymentGateway;
}
}A concise interview answer is
When there are multiple beans of the same type, plain @Autowired throws a NoUniqueBeanDefinitionException, so I pair it with @Qualifier to name the exact bean I want. Mixing in @Primary as a default is fine, but if @Qualifier values are misspelled or inconsistent across the codebase, it becomes unclear which implementation actually gets wired in, so I keep qualifier names deliberate and consistent.
Last updated: 16 July 2026
Previous question: Have you seen real-world bugs caused by choosing PUT instead of POST (or the reverse)? How were they fixed?