- 包/类型匹配:within
//匹配ProductService类里头的所有方法
@Pointcut("within(com.abc.service.ProductService)")
//匹配com.imooc包及子包下所有类的方法
@Pointcut("within(com.abc..*)")
- 匹配对象:this, target, bean
//匹配AOP对象的目标对象为指定类型的方法,即LogService的aop代理对象的方法
@Pointcut("this(com.abc.log.Loggable)")
//匹配实现Loggable接口的目标对象(而不是aop代理后的对象)的方法
@Pointcut("target(com.abc.log.Loggable)")
//this 可以拦截 DeclareParents(Introduction)
//target 不拦截 DeclareParents(Introduction)
//匹配所有以Service结尾的bean里头的方法
@Pointcut("bean(*Service)")
- 参数匹配:args
//匹配任何以find开头而且只有一个Long参数的方法
@Pointcut("execution(* *..find*(Long))")
//匹配任何以find开头的而且第一个参数为Long型的方法
@Pointcut("execution(* *..find*(Long,..))")
//匹配任何只有一个Long参数的方法
@Pointcut("within(com.abc..*) && args(Long)")
//匹配第一个参数为Long型的方法
@Pointcut("within(com.abc..*) && args(Long,..)")
- 匹配注解:execution
//匹配任何公共方法
@Pointcut("execution(public * com.abc.service.*.*(..))")
//匹配com.imooc包及子包下Service类中无参方法
@Pointcut("execution(* com.abc..*Service.*())")
//匹配com.imooc包及子包下Service类中的任何只有一个参数的方法
@Pointcut("execution(* com.abc..*Service.*(*))")
//匹配com.imooc包及子包下任何类的任何方法
@Pointcut("execution(* com.abc..*.*(..))")
//匹配com.imooc包及子包下返回值为String的任何方法
@Pointcut("execution(String com.abc..*.*(..))")
//匹配异常
execution(public * com.abc.service.*.*(..) throws java.lang.IllegalAccessException)