美文网首页
Spring(5) -(14) pointcut 语法

Spring(5) -(14) pointcut 语法

作者: 小白201808 | 来源:发表于2018-09-26 09:41 被阅读23次

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

    相关文章

      网友评论

          本文标题:Spring(5) -(14) pointcut 语法

          本文链接:https://www.haomeiwen.com/subject/plqdoftx.html