gpt4 book ai didi

aop - 如何从aspectj中排除方法

转载 作者:行者123 更新时间:2023-12-04 13:27:23 25 4
gpt4 key购买 nike

我正在尝试使用 aspectj 从日志文件中排除几种方法(我使用 spring 和加载时编织)。有没有办法在 aop.xml 中列出排除的方法?我知道我可以为完整的类(class)做到这一点,但我正在寻找特定的方法。或者我可以在方面类中列出一个列表吗?
谢谢

最佳答案

我不知道如何在 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(){}

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

关于aop - 如何从aspectj中排除方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com