如何从AspectJ中排除方法 [英] How to exclude methods from aspectj
问题描述
我正在尝试使用Aspectj从日志文件中排除几种方法(即使用spring和Load-time weaving).有没有办法在aop.xml中列出排除的方法?我知道我可以为完整课程做这件事,但是我正在寻找特定的方法.或者我可以在方面类中列出清单? 谢谢
I'm trying to exclude several methods from log files using aspectj (Im usong spring and Load-time weaving). Is there a way to list the excluded methods in the aop.xml? I know i can do this for full classes but I'm looking for specific methods. or can i make a list in the aspect class? Thanks
推荐答案
我不知道如何在XML中进行操作,但是在方面本身就很容易做到,因为切入点可以使用布尔运算符进行组合
I don't know how to do it in an XML, but it's easy enough to do it in the aspects themselves, as pointcuts can be combined using boolean operators.
传统aspectj语法:
Traditional aspectj syntax:
pointcut whatIDontWantToMatch() : within(SomeClass+) || execution(* @SomeAnnotation *.*(..));
pointcut whatIWantToMatch() : execution(* some.pattern.here.*(..));
pointcut allIWantToMatch() : whatIWantToMatch() && ! whatIDontWantToMatch();
@AspectJ语法:
@AspectJ syntax:
@Pointcut("within(SomeClass+) || execution(* @SomeAnnotation *.*(..))")
public void whatIDontWantToMatch(){}
@Pointcut("execution(* some.pattern.here.*(..))")
public void whatIWantToMatch(){}
@Pointcut("whatIWantToMatch() && ! whatIDontWantToMatch()")
public void allIWantToMatch(){}
这些当然只是示例. whatIDontWantToMatch()
也可以由多个切入点等组成.
These are of course just samples. whatIDontWantToMatch()
could also be composed of several pointcuts etc.
这篇关于如何从AspectJ中排除方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!