Consider the following situation:
class A() {
void a();
}
@MyAnnotation
class B extends A {
void b();
}
I want to advice all methods of all classes annotated with @MyAnnotation (i.e B.a()).
That’s pretty easy task due to the possibility of using @target pointcut expression.
BUT! in that case all beans in a container (even unsuitable) will be Proxified what is unacceptable.
Now the question: Is it possible to build up pointcut expressino without @target but with the same effect?
You can use within like this.
refer to https://stackoverflow.com/a/2522821/672586 and http://forum.springsource.org/showthread.php?28525-Difference-between-target-and-within-in-Spring-AOP for more details. The relevant section from the forum post explaining the difference between within and target
One difference between the two is that @within() is matched statically, requiring the corresponding annotation type to have only the CLASS retention. Whereas, @target() is matched at runtime, requiring the same to have the RUNTIME retention. Other than that, within the context of Spring, there is no difference between the join points selected by two.