June 2018
Intermediate to advanced
408 pages
11h 23m
English
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 ...Read now
Unlock full access