spring Dependency Injection (DI) and Inversion of Control (IoC) Autowiring a dependency through Java configuration


Example

Constructor injection through Java configuration can also utilize autowiring, such as:

@Configuration
class AppConfig {
  @Bean
  public Bar bar() { return new Bar(); }

  @Bean
  public Foo foo(Bar bar) { return new Foo(bar); }
}