<context:include-filter>和 <context:exclude-filter>春季上班? [英] How do <context:include-filter> and <context:exclude-filter> work in Spring?
问题描述
我有几项服务:
- example.MailService
- example.LDAPService
- example.SQLService
- example.WebService
- example.ExcelService
使用 @Service
注释进行注释.如何排除除一项之外的所有服务?
annotated with @Service
annotation. How can I exclude all services except one?
例如,我只想使用 MailService.我使用以下配置:
<context:component-scan base-package="example">
<context:include-filter type="aspectj" expression="example..MailService*" />
<context:exclude-filter type="aspectj" expression="example..*Service*" />
</context:component-scan>
但现在所有服务都被排除在外.
but now all services are excluded.
如果存在一个包含 MailService 的规则,为什么要排除所有服务?
Why all services are excluded if exists one rule to include MailService?
推荐答案
包含过滤器应用在排除过滤器之后,因此您必须将两个表达式合并为一个排除过滤器.AspectJ 表达式允许它(由于 XML 语法,&
被替换为 &
):
Include filters are applied after exclude filters, so you have to combine both expressions into one exclude filter. AspectJ expressions allow it (&
is replaced by &
due to XML syntax):
<context:exclude-filter type="aspectj"
expression="example..*Service* && !example..MailService*" />
这是一个正则表达式,因此您的表达式.*Service"表示任意数量的任何字符后跟Service"".这明确排除了您要包含的 MailService.
This is a regex, so your expression ".*Service" means 'any number of any character followed by "Service"'. This explicitly excludes the MailService you want to include.
这篇关于<context:include-filter>和 <context:exclude-filter>春季上班?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!