Different patterns of execution syntax

We took these from spring official website please refer. Not required to remember syntax but try understanding concept behind this.

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..*.*(..))

  • any join point (method execution only in Spring AOP) within the service package:

  • within(com.xyz.service.*)

  • any join point (method execution only in Spring AOP) within the service package or a sub-package:

  • within(com.xyz.service..*)

  • any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface:

  • this(com.xyz.service.AccountService)

Another way of writing this is to declare a pointcut that "provides" the Account object value when it matches a join point, and then just refer to the named pointcut from the advice.

This would look as follows:

In this pattern pointcut is defined as expression then it is used with advice, observe argument account here.


AOP also has schema based support. Sample is like below but not needed usually.