我正在尝试使用Aspectj从日志文件中排除几种方法(即使用spring和Load-time编织)。有没有办法在aop.xml中列出排除的方法?我知道我可以为完整类(class)做这件事,但是我正在寻找特定的方法。或者我可以在方面类中列出 list ?
谢谢

最佳答案

我不知道如何在XML中进行操作,但是在方面本身就很容易做到,因为切入点可以使用 bool 运算符进行组合。

传统aspectj语法:

pointcut whatIDontWantToMatch() : within(SomeClass+) || execution(* @SomeAnnotation *.*(..));
pointcut whatIWantToMatch()     : execution(* some.pattern.here.*(..));
pointcut allIWantToMatch()      : whatIWantToMatch() && ! whatIDontWantToMatch();

@AspectJ语法:
@Pointcut("within(SomeClass+) || execution(* @SomeAnnotation *.*(..))")
public void whatIDontWantToMatch(){}
@Pointcut("execution(* some.pattern.here.*(..))")
public void whatIWantToMatch(){}
@Pointcut("whatIWantToMatch() && ! whatIDontWantToMatch()")
public void allIWantToMatch(){}

这些当然只是示例。 whatIDontWantToMatch()也可以由几个切入点等组成。

10-07 13:14