AND、OR 和 NOT 的 Spring AOP 切入点语法 [英] Spring AOP Pointcut syntax for AND, OR and NOT

查看:30
本文介绍了AND、OR 和 NOT 的 Spring AOP 切入点语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Spring(2.5.6 版)中遇到了切入点定义的问题.我正在尝试拦截对类的所有方法调用,除了给定的方法(下面示例中的 someMethod).

I'm having trouble with a pointcut definition in Spring (version 2.5.6). I'm trying to intercept all method calls to a class, except for a given method (someMethod in the example below).

<aop:config>
    <aop:advisor
         pointcut="execution(* x.y.z.ClassName.*(..)) AND NOT
                   execution(* x.y.x.ClassName.someMethod(..))"
    />
</aop:config>

但是,拦截器也会为 someMethod 调用.

However, the interceptor is invoked for someMethod as well.

然后我尝试了这个:

<aop:config>
    <aop:advisor
         pointcut="execution(* x.y.z.ClassName.(* AND NOT someMethod)(..)) )"
    />
</aop:config>

但这不能编译,因为它不是有效的语法(我得到一个 BeanCreationException).

But this does not compile as it is not valid syntax (I get a BeanCreationException).

谁能给点建议?

推荐答案

我知道在这个阶段它可能有点晚了,但我遇到了同样的问题,我通过转义 & 字符解决了它,所以它的 &amp;&amp;! 而不是 'AND NOT' 或 '&&!'.我在 xml 文件中这样做

i know its probably a bit late at this stage but ive been having the same issue and I resolved it by escaping the ampersand chars so its &amp;&amp; ! instead of 'AND NOT' or '&& !'. I'm doing this in the xml file

<aop:config>
    <aop:pointcut id="blah" expression="execution(* com.disney.goofy..*.*(..)) &amp;&amp; !@annotation(com.disney.goofy.NonDisneyCharacter)"/>
    <aop:advisor advice-ref="transAdvice" pointcut-ref="blah"/>
</aop:config>

这将建议应用于在 com.disney.goofy 中执行且未使用 NonDisneyCharacter 注释的所有方法

This applies the advice to all methods executed in com.disney.goofy and that are not annotated with NonDisneyCharacter

这篇关于AND、OR 和 NOT 的 Spring AOP 切入点语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆