对于您的问题1-
是的,您可以使用
@ComponentScan在 spring容器* 中注册的 任何 配置Bean
来注册Bean。您可以通过以下任何一种方式将Bean注册到容器中: *
- 用于
@Configuration
在rootcontext
或中 注册beandispatchersevletcontext
。 - 将类导入任何
@Configuration
Bean(已在容器中注册)。
假设-您有
MvcConfig要扫描组件的类-
@ComponentScan(basePackages = {"xxxx","yyyy","zzzz"})@Configurationpublic class MvcConfig {....}要
MvcConfig在容器中注册,您必须执行以下操作:
要么
new AnnotationConfigWebApplicationContext().register(MvcConfig.class);
要么
new AnnotationConfigWebApplicationContext().register(AnotherConfig.class);@Configuration@import({MvcConfig.class})public class AnotherConfig {....}对于您的问题2-
在这里,spring不仅要注册
MyConfiguration.class,还要注册
MyConfiguration定义的包中存在的所有组件类。



