Spring基于注解的容器配置上下文:include &排除过滤器
首先,我指出类似的问题。我花了一个多小时来设置它,但 PathMatchingResourcePatternResolver 仍然扫描所有内容。
我有一个 common.xml (从 Specific.xml 导入)和一个 Specific.xml bean 定义文件。上下文是从 Specific.xml 加载的。在 common.xml 中有这个元素:
<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 将所有内容标记为匹配资源。与正则表达式相同。
编辑:如果我在 Specific.xml 中声明 context:component-scan ,那么扫描甚至不会开始,并且我在 common.xml 中基于注释的依赖项上得到 NoSuchBeanDefinitionException 。
顺便说一句:在 xml 样式配置中,可以有许多组件在加载上下文时通过“导入资源”共享一个 common.xml beans。当使用基于注释的容器配置时,这是如何完成的?
first off I point to the similar question. I spent more than an hour to set this up, but PathMatchingResourcePatternResolver still scans everything.
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>
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: 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: 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,您需要“或”而不是“和”:
In this case you need "or" rather than "and":