I'm just starting to learn the Spring framework (I'm using version 4.3.0), and I thought we needed @Autowired to talk about the structure when a class needs an injection.
However, today I try:
@Component
public class CDPlayer implements MediaPlayer{
private CompactDisc cd;
public CDPlayer(CompactDisc cd) {
this.cd = cd;
}
public void play() {
cd.play();
}
}
and it works great with automatic wiring configuration:
@Configuration
@ComponentScan
public class CDPlayerConfigAuto {
}
So, when do I really need to use @Autowired?
source
share