Am I correct, thinking that @Bean and @Component annotations are the same, but first is for classes and another is for methods?
In both cases container just creates appropriate beans, right?
Am I correct, thinking that @Bean and @Component annotations are the same, but first is for classes and another is for methods?
In both cases container just creates appropriate beans, right?
Not quite. They belong to different concepts.
@Component
is a stereotype annotation. A class annotated with this annotation will be auto detected during class path scanning. See also Spring reference documentation chapter 5.10. Other than that the @Bean
annotation belongs to the Java configuration feature. Within a configuration class this annotation is used to mark methods that define beans.