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(..))")
How do I update this to only execute for classes that are annotated with my @MyCustomAnnotation
annotation
I use this for method invocation:
within(@MyCustomAnnotation *)
So, the resulting aspect code would be:
@Before("execution(*.new(..)) && within(@MyCustomAnnotation *)")
Alternatively, try this:
@Pointcut("execution(@MyCustomAnnotation *.new(..))")
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.