方法签名匹配:
expression(<method scope> <return type> <fully qualified class name>.*(parametes))
method scope: Advice will be applied to all the methods having this
scope. For e.g., public, private, etc. Please note that Spring AOP
only supports advising public methods.return type: Advice will be applied to all the methods having this
return type.fully qualified class name: Advice will be applied to all the methods
of this type. If the class and advice are in the same package then
package name is not requiredparameters: You can also filter the method names based on the types.
Two dots(..) means any number and type of parameters.
示例:
execution(* com.aspects.pointcut.DemoClass.*(..)) 匹配DemoClass下所有的方法。
execution(public com.aspects.pointcut.DemoClass.*(int,int)) 匹配DemoClass下public、参数为两个int的方法。
类型签名匹配:
适用于类型符合的多有joinpoint
within(type name)
“type name”可以使包名称也可以是类名称
示例:
within(com.aspects.blog.package.*) : 匹配 com.aspects.blog.package包下所有类的所有方法。(注意:com.aspects.blog.package.abc下的类方法并不匹配)
within(com.aspects.blog.package..*) 匹配 com.aspects.blog.package包下所有类的所有方法,并且匹配其子包下所有类的所有方法。
within(com.aspects.blog.package.DemoClass) 匹配com.aspects.blog.package.DemoClass下所有方法
within(com.aspects.blog.package.DemoInterface+) : 匹配这个接口的所有实现类的所有方法
AOP表达式逻辑计算
Pointcut expressions can be combined using && (and), ||(or), and !(not).
within(com.aspects.blog.package.DemoInterface+)|| within(com.aspects.blog.package.DemoInterface2+)
匹配DemoInterface或者DemoInterface2的实现类中的所有方法
更多示例:
//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)
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html