AND、OR 和 NOT 的 Spring AOP 切入点语法
我在 Spring(版本 2.5.6)中的切入点定义时遇到问题。我试图拦截对类的所有方法调用,除了给定的方法(下面示例中的 someMethod )。
<aop:config>
<aop:advisor
pointcut="execution(* x.y.z.ClassName.*(..)) AND NOT
execution(* x.y.x.ClassName.someMethod(..))"
/>
</aop:config>
然而,拦截器也会被 someMethod 调用。
然后我尝试了这个:
<aop:config>
<aop:advisor
pointcut="execution(* x.y.z.ClassName.(* AND NOT someMethod)(..)) )"
/>
</aop:config>
但这不会编译,因为它不是有效的语法(我得到一个 BeanCreationException)。
有人可以提供任何提示吗?
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>
However, the interceptor is invoked for someMethod as well.
Then I tried this:
<aop:config>
<aop:advisor
pointcut="execution(* x.y.z.ClassName.(* AND NOT someMethod)(..)) )"
/>
</aop:config>
But this does not compile as it is not valid syntax (I get a BeanCreationException).
Can anybody give any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道在这个阶段可能有点晚了,但我也遇到了同样的问题,我通过转义 & 字符解决了它,所以它的
&& !
而不是“AND NOT”或“&&” !'。我在 xml 文件中执行此操作,
这将建议应用于 com.disney.goofy 中执行的所有方法,并且未使用 NonDisneyCharacter 进行注释
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
&& !
instead of 'AND NOT' or '&& !'.I'm doing this in the xml file
This applies the advice to all methods executed in com.disney.goofy and that are not annotated with NonDisneyCharacter
这应该可以工作(spring AOP参考):
This should work (spring AOP reference):
我也在使用 spring 2.5.6,并且遇到了类似的问题,OR 不工作,但 AND 正在工作。事实证明,或(小写)确实有效,因此该代码中显然存在错误。
有趣的是,正确的aspectJ语法是&&、||和!,但是and/or/not语法是由 spring 添加,使 xml 工作更容易。从手册中:
我猜想,由于 && 是唯一在 xml 中实际上很尴尬的一个(在 xml 中放入 | 或 ! 没有什么困难),那么 AND 是唯一经过正确测试的
I'm also using spring 2.5.6 and was having a similar problem with OR not working, but AND was working. It turns out that or (in lowercase) does work, so there is clearly a bug in that code.
It is interesting that the proper aspectJ syntax is &&, ||, and !, but the and/or/not syntax was added by spring to make working in xml easier. From the manual:
I would guess that since && is the only one that is actually awkward in xml (there is nothing difficult about putting | or ! in xml) then AND is the only one that was properly tested