В моем файле конфигурации Java есть
@Bean
public CDPlayer cdPlayer(CompactDisc compactDisc){
return new CDPlayer(compactDisc);
}
В моей книге говорится, что (singleton) CompactDisc автоматически подключается к методу. Почему? Потому что не вижу @Autowired. Как это может работать?
Этот вопрос объясняет разницу между ними: stackoverflow.com/questions/34172888/…




A @Bean annotated method can have an arbitrary number of parameters describing the dependencies required to build that bean
The resolution mechanism is pretty much identical to constructor-based dependency injection, see the relevant section for more details.
Каждый параметр в методе @Bean будет разрешен (введен контейнером Spring).
Начиная с Spring 4.3 вам не нужно использовать аннотацию @Autowired для внедрения зависимости