In book Spring in Action, I found following AspectJ point cut expression:
@Pointcut("execution(** concert.Performance.perform(..))")
void performance();
This will designate point cut performance to include methods whose name is "perform" and whose return type can be any. But notice it uses two stars (**) to match the return type, as I've experimented, one star (*) can perfectly do the job, this means the following line can do the same thing:
@Pointcut("execution(* concert.Performance.perform(..))")
void performance();
And I noticed that many AspectJ demos use two stars (**) to match "any return type", so is there some reason to do so? What is the problem of using one star to match "any return type"?
JoinPoint: Joinpoint are points in your program execution where flow of execution got changed like Exception catching, Calling other method. PointCut: PointCut are basically those Joinpoints where you can put your advice(or call aspect). So basically PointCuts are the subset of JoinPoints.
Explanation: Union means the methods that either pointcut matches. Intersection means the methods that both pointcuts match. Union is usually more useful. Explanation: Using the static methods in the org.
AspectJ provides primitive pointcuts that capture join points at these times. These pointcuts use the dynamic types of their objects to pick out join points. They may also be used to expose the objects used for discrimination. this(Type or Id) target(Type or Id)
@target – pointcut expression for matching to join points where the class of the executing object has an annotation of the given type. @args – pointcut expression for matching to join points where the runtime type of the actual arguments passed have annotations of the given type.
After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return). Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice.
Spring documentation helps understand this better. It says
Spring AOP users are likely to use the execution pointcut designator the most often. The format of an execution expression is:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern) throws-pattern?)
The first part modifiers-pattern
is optional as you can see it has suffixed with ?
. This is to designate method's access type.
So in your case, pointcut expression execution(** concert.Performance.perform(..))
advises execution of methods with any access modifier and any return type on the type concert.Performance
with method name perform
that has any argument type.
execution(* concert.Performance.perform(..))
means the same where the first *
is optional that denotes perform
method on the type concert.Performance
that accepts any type of arguments and method may have any return type(with optional access modifier meaning that access modifier can be anything).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With