Reputation: 1729
I had being using the JSR 330 @Inject annotation to autowire my Spring beans. I started experimenting by removing the @Inject annotation - yet my application context still gets loaded correctly. Not sure if this is expected and cant find any spring documentation to verify this use case.
// This context is loaded correctly - and beans exist for B, C and Db
final ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
@Import({ B.class })
@Configuration
public class ApplicationConfig {
@Bean
public Db db() {
return new Database();
}
@Bean
// I thought this method would need an @Autowire or @Inject annotation to resolve b!?
public C c(final B b){
return new C(b);
}
}
@Configuration
public class BConfig {
@Bean
public B b() {
return new B();
}
}
Upvotes: 0
Views: 329
Reputation: 58134
@Autowired
(or @Inject
if you prefer) is implicit in @Bean
methods (always has been as far as I know).
Upvotes: 2