相关疑难解决方法(0)

过滤@ComponentScan中的特定包

我想在Spring中从基于XML的配置切换到基于Java的配置.现在我们在应用程序上下文中有这样的东西:

<context:component-scan base-package="foo.bar">
    <context:exclude-filter type="annotation" expression="o.s.s.Service"/>
</context:component-scan>
<context:component-scan base-package="foo.baz" />
Run Code Online (Sandbox Code Playgroud)

但如果我写这样的东西......

 @ComponentScan(
    basePackages = {"foo.bar", "foo.baz"},
    excludeFilters = @ComponentScan.Filter(
       value= Service.class, 
       type = FilterType.ANNOTATION
    )
 )
Run Code Online (Sandbox Code Playgroud)

...它将从两个包中排除服务.我有强烈的感觉,我忽略了一些令人尴尬的琐碎,但我找不到一个解决方案来限制过滤器的范围foo.bar.

spring annotations

35
推荐指数
1
解决办法
5万
查看次数

标签 统计

annotations ×1

spring ×1