If you have multiple beans of the same type in your Spring application context, how would you handle conflicts using @Autowired and @Qualifier? What potential issues could arise if you mix these annotations incorrectly?

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.

Key Points

Example

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;
    }
}

Interview Tip

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?

Next question: If your application needs to handle file uploads, which controller would you prefer and why? Can you describe a scenario where using a @RestController could lead to complications?

More Spring Boot - Level V (Expert) interview questions

All Spring Boot - Level V (Expert) questions