October 2017
Intermediate to advanced
396 pages
10h 2m
English
The @Autowiring annotation reduces verbosity in the code, but it may create some problems when two of the same type of beans exist in the container. Let's see what happens in that situation, with the following example:
@Service
public class TransferServiceImpl implements TransferService {
@Autowired
public TransferServiceImpl(AccountRepository accountRepository) { ... }
}
The preceding snippet of code shows that the TransferServiceImpl class has a dependency with a bean of type AccountRepository, but the Spring container contains two beans of the same type, that is, the following:
@Repository
public class JdbcAccountRepository implements AccountRepository {..} @Repository public class JpaAccountRepository ...Read now
Unlock full access