October 2017
Intermediate to advanced
396 pages
10h 2m
English
Spring provides one more annotation, @Qualifier, to overcome the problem of disambiguation in autowiring DI. Let's see the following snippet of code with the @Qualifier annotation:
@Service
public class TransferServiceImpl implements TransferService {
@Autowired
public TransferServiceImpl( @Qualifier("jdbcAccountRepository") AccountRepository accountRepository) { ... }
Now I have wired the dependency by name rather than by type by using the @Qualifier annotation. So, Spring will search the bean dependency with the name "jdbcAccountRepository" for the TransferServiceImpl class. I have given the names of the beans as follows:
@Repository("jdbcAccountRepository") public class JdbcAccountRepository ...Read now
Unlock full access