Spring annotation-based container configuration context:include & exclude filters

荒凉一梦 提交于 2020-01-06 19:17:08

问题


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..* &amp;&amp; cz.instance.transl.service..* &amp;&amp; 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 ?


回答1:


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..*"/>       


来源:https://stackoverflow.com/questions/4584509/spring-annotation-based-container-configuration-contextinclude-exclude-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!