美文网首页
Aop 表达式

Aop 表达式

作者: jianghushao | 来源:发表于2021-10-14 16:27 被阅读0次

    【转载至】https://cloud.tencent.com/developer/article/1552285

    execute
    within
    this
    target
    args
    @target
    @within
    @annotation
    @args
    

    示例代码git地址
    https://gitee.com/likun_557/spring-aop-demo

    1.execute表达式
    拦截任意公共方法
    execution(public * *(..))
    
    拦截以set开头的任意方法
    execution(* set*(..))
    
    拦截类或者接口中的方法
    execution(* com.xyz.service.AccountService.*(..))
    拦截AccountService(类、接口)中定义的所有方法
    
    拦截包中定义的方法,不包含子包中的方法
    execution(* com.xyz.service.*.*(..))
    拦截com.xyz.service包中所有类中任意方法,不包含子包中的类
    
    拦截包或者子包中定义的方法
    execution(* com.xyz.service..*.*(..))
    拦截com.xyz.service包或者子包中定义的所有方法
    
    
    2.within表达式
    表达式格式:包名.* 或者 包名..*
    
    拦截包中任意方法,不包含子包中的方法
    within(com.xyz.service.*)
    拦截service包中任意类的任意方法
    
    拦截包或者子包中定义的方法
    within(com.xyz.service..*)
    拦截service包及子包中任意类的任意方法
    
    
    3.this表达式
    代理对象为指定的类型会被拦截
    目标对象使用aop之后生成的代理对象必须是指定的类型才会被拦截,注意是目标对象被代理之后生成的代理对象和指定的类型匹配才会被拦截
    
    this(com.xyz.service.AccountService)
    示例
    this表达式的使用,可能不是很好理解,用示例说明一下:
    

    相关文章

      网友评论

          本文标题:Aop 表达式

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