栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

筛选@ComponentScan中的特定软件包

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

筛选@ComponentScan中的特定软件包

你只需要为

Config
所需的两个
@ComponentScan
注释创建两个类。

因此,例如

Config
,你的
foo.bar
包装将有一个类:

@Configuration@ComponentScan(basePackages = {"foo.bar"},     excludeFilters = @ComponentScan.Filter(value = Service.class, type = FilterType.ANNOTATION))public class FooBarConfig {}

然后是

Config
你的
foo.baz
包裹的二等舱:

@Configuration@ComponentScan(basePackages = {"foo.baz"})public class FooBazConfig {}

然后在实例化Spring上下文时,你将执行以下操作:

new AnnotationConfigApplicationContext(FooBarConfig.class, FooBazConfig.class);

另一种选择是,你可以@org.springframework.context.annotation.import在第一Config类上使用批注来导入第二Config类。因此,例如,你可以更改FooBarConfig为:

@Configuration@ComponentScan(basePackages = {"foo.bar"},     excludeFilters = @ComponentScan.Filter(value = Service.class, type = FilterType.ANNOTATION))@import(FooBazConfig.class)public class FooBarConfig {}

然后,你只需从以下内容开始上下文:

new AnnotationConfigApplicationContext(FooBarConfig.class)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/404932.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号