AOP – how to exclude methods from AspectJ

I'm trying to use AspectJ to exclude several methods from log files (I only use spring and load time weaving) Is there any way to list AOP Exclusion methods in XML? I know I can do this for the whole class, but I'm looking for specific ways Or can I make a list in the aspect class?

Solution

I don't know how to do this in XML, but it's easy to do this in the aspect itself, because you can use Boolean operators to combine pointcuts

Traditional AspectJ syntax:

pointcut whatIDontWantTomatch() : within(SomeClass+) || execution(* @SomeAnnotation *.*(..));
pointcut whatIWantTomatch()     : execution(* some.pattern.here.*(..));
pointcut allIWantTomatch()      : whatIWantTomatch() && ! whatIDontWantTomatch();

@AspectJ syntax:

@pointcut("within(SomeClass+) || execution(* @SomeAnnotation *.*(..))")
public void whatIDontWantTomatch(){}
@pointcut("execution(* some.pattern.here.*(..))")
public void whatIWantTomatch(){}
@pointcut("whatIWantTomatch() && ! whatIDontWantTomatch()")
public void allIWantTomatch(){}

These are only samples, of course Whatidontwanttomatch () can also be composed of several pointcuts

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>