Spring基于注解的容器配置上下文:include &排除过滤器

发布于 2024-10-09 23:39:14 字数 948 浏览 0 评论 0原文

首先,我指出类似的问题。我花了一个多小时来设置它,但 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..* &amp;&amp; cz.instance.transl.service..* &amp;&amp; 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稚然 2024-10-16 23:39:14

在这种情况下,您需要“或”而不是“和”:

<context:exclude-filter type="aspectj"
     expression="cz.instance.transl.model..* || cz.instance.transl.service..* || cz.instance.transl.hooks..*"/>       

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..*"/>       
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文