Issue
@ComponentScan
creates beans using both @Configuration
and @Component
. Both these annotations work fine when swapped. What is the difference then?
Solution
@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:
A @Configuration is also a @Component, but a @Component cannot act like a @Configuration.
Answered By - reos
Answer Checked By - Pedro (JavaFixing Volunteer)