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?) All parts except the returning type pattern (ret-type-pattern in the snippet above), name pattern, and parameters pattern are optional. The returning type pattern determines what the return type of the method must be in order for a join point to be matched. Most frequently you will use * as the returning type pattern, which matches any return type. A fully-qualified type name will match only when the method returns the given type. The name pattern matches the method name.
You can use the * wildcard as all or part of a name pattern.
The parameters pattern is slightly more complex:
() matches a method that takes no parameters
(..) matches any number of parameters (zero or more)
(*) matches a method taking one parameter of any type,
(*,String) matches a method taking two parameters, the first can be of any type, the second must be a String.
Some examples of common pointcut expressions are given below.
the execution of any public method: execution(public * *(..))
the execution of any method with a name beginning with “set”: execution(* set*(..))
the execution of any method defined by the AccountService interface: execution(* com.xyz.service.AccountService.*(..))
the execution of any method defined in the service package: execution(* com.xyz.service.*.*(..))
the execution of any method defined in the service package or a sub-package: execution(* com.xyz.service..*.*(..))
@Around of advice
Around advice is declared using the @Around annotation.
The first parameter of the advice method must be of type ProceedingJoinPoint. Within the body of the advice, calling proceed() on the ProceedingJoinPoint causes the underlying method to execute. The proceed method may also be called passing in an Object[] - the values in the array will be used as the arguments to the method execution when it proceeds.