我想在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.