问题描述
我想用指定的注解(比如@Monitor)监视所有类的所有公共方法(注意:注解是在类级别).这可能是什么切入点?注意:我使用的是@AspectJ 风格的 Spring AOP.
I want to monitor all public methods of all Classes with specified annotation (say @Monitor) (note: Annotation is at class level). What could be a possible pointcut for this?Note: I am using @AspectJ style Spring AOP.
推荐答案
您应该将类型切入点与方法切入点结合起来.
You should combine a type pointcut with a method pointcut.
这些切入点将完成在标有@Monitor 注释的类中查找所有公共方法的工作:
These pointcuts will do the work to find all public methods inside a class marked with an @Monitor annotation:
@Pointcut("within(@org.rejeev.Monitor *)")
public void beanAnnotatedWithMonitor() {}
@Pointcut("execution(public * *(..))")
public void publicMethod() {}
@Pointcut("publicMethod() && beanAnnotatedWithMonitor()")
public void publicMethodInsideAClassMarkedWithAtMonitor() {}
建议结合前两个的最后一个切入点,你就完成了!
Advice the last pointcut that combines the first two and you're done!
如果你有兴趣,我已经写了一个备忘单 带有 @AspectJ 样式,带有相应的 示例文档在这里.
If you're interested, I have written a cheat sheet with @AspectJ style here with a corresponding example document here.
这篇关于@AspectJ 切入点用于具有特定注释的类的所有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!