您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

@ComponentScan具有多个配置类:基于注释的配置

@ComponentScan具有多个配置类:基于注释的配置

是的,您可以使用@ComponentScan在 *

假设-您有MvcConfig要扫描组件的类-

@ComponentScan(basePackages = {"xxxx","yyyy","zzzz"})
@Configuration
public class MvcConfig  {
....
}

MvcConfig在容器中注册,您必须执行以下操作:

要么

new AnnotationConfigWebApplicationContext().register(MvcConfig.class);

要么

new AnnotationConfigWebApplicationContext().register(AnotherConfig.class);

@Configuration
@Import({MvcConfig.class})
public class AnotherConfig  {
....
}

在这里,spring不仅要注册MyConfiguration.class,还要注册MyConfiguration定义的包中存在的所有组件类。

其他 2022/1/1 18:23:32 有488人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶