O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The @Qualifier annotation

Handling multiple autowire candidates with @Primary is more effective when only one primary candidate can be determined for multiple autowire candidates. The @Qualifier annotation gives you more control over the selection process. It allows you to give a reference associated with a specific bean type. That reference can be used to qualify the dependency that needs to be autowired. Let's look at the following code:

@Componentpublic class AccountService implements CustomerService {}@Component@Qualifier("BankingService")public class BankingService implements CustomerService { }@Componentpublic class SomeService {    private CustomerService customerService;  @Autowired  @Qualifier("bankingservice") public BankingService(CustomerService ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required