AOP的规范本应该由SUM公司提出,但是被AOP联盟捷足先登.AOP联盟指定AOP规范,首先就要解决一个问题,怎么表示切入点,也就是在哪些方法上增强(where)
AspectJ 是一个面向切面的框架:
AspectJ切入点语法如下:
(表示在哪些包下的哪些类的哪些方法做切入增强)
execution(modifiners-pattern?ret-type-pattern declaring-type-pattern? name-param(param-patterm)throws-pattern?) ?
表示:该参数可以出现一次或零次
翻译成中文: execution(
<修饰符>?<返回类型> <声明类型>?<方法名>(<参数>)<异常>?)
举例:public static Class java.lang.Class.forName(String className) throws ClassNotFoundException
通配符
*
匹配任何部分,只能表示一个单词
..
可用于全限定名中和方法参数中,分别表示子包和0到N个参数
spring-core 文档中的例子
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..*.*(..))//常用
作者:小白201808
链接:https://www.jianshu.com/p/f82b6933d78f
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。