具有多个注释的方法的 AspectJ 切入点 [英] AspectJ Pointcut on Methods with Multiple Annotations
本文介绍了具有多个注释的方法的 AspectJ 切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用加载时编织,纯 AspectJ.
Use load-time weaving, pure AspectJ.
我们有 2 个注释 @Time
和 @Count
,以及一些带注释的方法.
We have 2 annotations @Time
and @Count
, and a few annotated methods.
@Time (name="myMethod1Time")
@Count (name="myMethod1Count")
public void myMethod1(){..};
@Time (name="myMethod2Time")
public void myMethod2(){..};
@Count (name="myMethod3Count")
public void myMethod3(){..};
现在我正在为具有多个注释的 myMethod1
定义我自己的方面:
Now I am defining my own around aspect for myMethod1
which has multiple annotations:
// multiple annotations, not working
@Around("@annotation(time) && @annotation(count))
public Object myAspect(Time time, Count count) {..}
这不起作用.但是,捕获方法 myMethod2
使用单个注释可以正常工作:
This doesn't work. However, capture method myMethod2
works fine with a single annotation:
// single annotation, is working
@Around("@annotation(time))
public Object myAnotherAspect(Time time) {..}
我只想捕获签名中同时存在 Time
和 Count
注释的方法,并且我想使用注释值.有人知道如何实现这一目标吗?
I want to capture only methods with both Time
and Count
annotations present in their signature, and I want to use the annotation value. Anyone know how to achieve this?
推荐答案
也许结合 2 个切入点,例如:
Maybe combine 2 pointcuts like:
@Around("call(@Time * *(..)) && call(@Count * *(..))");
这篇关于具有多个注释的方法的 AspectJ 切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文