June 2018
Intermediate to advanced
408 pages
11h 23m
English
By default, in Spring Framework, DI is done by type, which means that when there are multiple dependencies with the same type, the NoUniqueBeanDefinitionException exception will be thrown. It indicates that the Spring container is unable to select a bean for DI because of more than one eligible candidate. In that case, we can use the @Primary annotation and take control of the selection process. Let's see the following code:
public interface CustomerService { public void customerService(); }@Componentpublic class AccountService implements CustomerService { ....}@Component@Primarypublic class BankingService implements CustomerService { ....}
In the case of the previous example, there are two customer services available: ...
Read now
Unlock full access