具有特定注释的类的所有方法的@AspectJ切入点 [英] @AspectJ pointcut for all methods of a class with specific annotation

查看:139
本文介绍了具有特定注释的类的所有方法的@AspectJ切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望监视具有指定注释的所有类的所有公共方法(比如@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!

如果你有兴趣,我写了备忘单,带有相应的 example document here。

If you're interested, I have written a cheat sheet with @AspectJ style here with a corresponding example document here.

这篇关于具有特定注释的类的所有方法的@AspectJ切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆