@ComponentScan creates beans using both @Configuration and @Component. Both these annotations work fine when swapped. What is the difference then?
@ComponentScan
@Configuration
@Component
@Configuration Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime @Component Indicates that an annotated class is a "component". Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning. @Configuration is meta-annotated with @Component, therefore @Configuration classes are candidates for component scanning
@Configuration Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime
@Component Indicates that an annotated class is a "component". Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning.
@Configuration is meta-annotated with @Component, therefore @Configuration classes are candidates for component scanning
You can see more here:
http://docs.spring.io/spring-framework/docs/4.0.4.RELEASE/javadoc-api/org/springframework/context/annotation/Configuration.html
A @Configuration is also a @Component, but a @Component cannot act like a @Configuration.
1.4m articles
1.4m replys
5 comments
57.0k users