0

In my Java Config file there is

@Bean
public CDPlayer cdPlayer(CompactDisc compactDisc){
    return new CDPlayer(compactDisc);
}

My book says that the (singleton) CompactDisc is autowired into the method. Why? Because I do not see @Autowired. How can this work?

namokarm
  • 668
  • 1
  • 7
  • 20
ericj
  • 2,138
  • 27
  • 44

1 Answers1

5

About @Bean in Spring

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.

Every parameter in a @Bean method will be resolved (injected by Spring container).

Community
  • 1
  • 1
Mạnh Quyết Nguyễn
  • 17,677
  • 1
  • 23
  • 51