用于构造函数调用的AspectJ Pointcut [英] AspectJ Pointcut for constructor invocation
问题描述
我正在尝试编写一条建议,以使用自定义注释来拦截对类的构造函数的调用:
I am trying to write an advice to intercept the calls to constructors of a class with my custom annotation:
@MyCustomAnnotation
public class SomeClass {
public SomeClass(Foo a, Bar b){
...
}
public SomeClass(Foo a){
this(a, null);
}
}
我通常看到一个如何拦截构造函数调用的示例:
I see an example of how to intercept constructor calls, in general:
@Before("execution(*.new(..))")
我如何更新它以仅对使用我的 @MyCustomAnnotation
批注进行批注的类执行
How do I update this to only execute for classes that are annotated with my @MyCustomAnnotation
annotation
推荐答案
我将其用于方法调用:
within(@MyCustomAnnotation *)
因此,最终的方面代码将是:
So, the resulting aspect code would be:
@Before("execution(*.new(..)) && within(@MyCustomAnnotation *)")
或者,尝试以下操作:
@Pointcut("execution(@MyCustomAnnotation *.new(..))")
我在这里指的是文档: https://blog.espenberntsen.net/2010/03/20/aspectj-cheat-sheet/
I am referring to the documentation here: https://blog.espenberntsen.net/2010/03/20/aspectj-cheat-sheet/
而且,它应该在理论上可行,但是我没有任何运气.
and, it should work in theory, but I am not having any luck.
这篇关于用于构造函数调用的AspectJ Pointcut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!