基于Spring注释的容器配置上下文:包括&排除过滤器 [英] Spring annotation-based container configuration context:include & exclude filters
问题描述
首先我指向类似的问题。我花了一个多小时来设置它,但PathMatchingResourcePatternResolver仍然扫描所有内容。
first off I point to the similar question. I spent more than an hour to set this up, but PathMatchingResourcePatternResolver still scans everything.
我有一个common.xml(从specific.xml导入) .xml bean定义文件。上下文从specific.xml加载。在common.xml中有这个元素:
I have one common.xml (that is imported from specific.xml) and a specific.xml bean definition file. The context is loaded from specific.xml. In common.xml there is this element:
<context:component-scan base-package="cz.instance.transl">
<context:exclude-filter type="aspectj"
expression="cz.instance.transl.model..* && cz.instance.transl.service..* && cz.instance.transl.hooks..*"/>
</context:component-scan>
在cz.instance.transl.service。*等软件包中的类不应进行扫描,但是这里的一切cz.instance.transl。*应该扫描通过。但PathMatchingResourcePatternResolver将所有内容标记为匹配资源。它与regex是一样的。
Where classes in packages like cz.instance.transl.service.* should not be subject of scanning, but everything else in here cz.instance.transl.* should be scanned through. But PathMatchingResourcePatternResolver marks everything as matching resources. It is the same with regex.
EDITED:如果我声明context:component-scan在specific.xml中,那么扫描甚至不会启动,我得到NoSuchBeanDefinitionException在common.xml中基于注释的依赖性。
EDITED: If I declare context:component-scan in specific.xml, then the scanning doesn't even start, and I get NoSuchBeanDefinitionException on annotation based dependencies in common.xml.
BTW:在xml样式配置中,可以有许多组件通过import resource上下文。当使用基于注释的容器配置时如何做?
BTW: in xml style configuration, one can have many components that share a common.xml beans via "import resource" when loading context. How this is done when Annotation-based container configuration is used ?
推荐答案
在这种情况下,您需要或而不是和:
In this case you need "or" rather than "and":
<context:exclude-filter type="aspectj"
expression="cz.instance.transl.model..* || cz.instance.transl.service..* || cz.instance.transl.hooks..*"/>
这篇关于基于Spring注释的容器配置上下文:包括&排除过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!