是的,您可以使用@ComponentScan
在 *
假设-您有MvcConfig
要扫描组件的类-
@ComponentScan(basePackages = {"xxxx","yyyy","zzzz"})
@Configuration
public class MvcConfig {
....
}
要么
new AnnotationConfigWebApplicationContext().register(MvcConfig.class);
要么
new AnnotationConfigWebApplicationContext().register(AnotherConfig.class);
@Configuration
@Import({MvcConfig.class})
public class AnotherConfig {
....
}
在这里,spring不仅要注册MyConfiguration.class
,还要注册MyConfiguration
定义的包中存在的所有组件类。