As per Spring Doc-
Configures component scanning directives for use with @Configuration classes. Provides support parallel with Spring XML's
<context:component-scan>
element.
In my spring web application there are multiple files those are marked @Configuration
,in order to register @component
bean in spring container-
Question1- Can we use @ComponentScan
in any of the @Configuration
class or in all @Configuration
classes?
Question2-
Also I seen in spring doc
@Configuration
@ComponentScan(basePackageClasses = { MyConfiguration.class })
public class MyConfiguration extends WebMvcConfigurerAdapter {
...
}
Why here scanning for configuration class itself.
edit: Basically my understanding with @ComponentScan
is to scan and register stereo type bean(ex- @componant
,@Controller
,@Services
etc..),why we are registering @Configuration
Bean.
basePackageClasses
- clue's in the name. – Bentonbentonite@Component
,2-if needed how to know either we arebasePackageClasses
or not,3-why this is not needed in any@Configuration
class in real world app. – Ratable