zoukankan      html  css  js  c++  java
  • AOP JoinPoint

    在使用Spring AOP的过程中,经常需要使用到各种不同的JoinPoint的定义,Spring AOP遵循了AspectJ形式的JoinPoint的定义形式,但是Spring目前只支持部分的AspectJ形式的Joinpoint的定义,同时Spring AOP只支持方法级别的JoinPoint。以下是我在学习Spring开发者手册时总结的一些JoinPoint的定义,不完整,欢迎补充。 

    execution 方法签名需要满足execution中描述的方法签名
    within 包或者类型满足within中描述的包或者类型的类的所有非私有方法
    this Spring AOP 的代理实例的类型满足this中的描述的类型
    target 业务实例对象(非代理实例)的类型满足target 中的描述的类型
    args 方法的参数满参数类型为args中描述的类型
    @target 类型拥有@target描述中给出的annotation
    @args 方法运行时传入的参数的实际类型拥有@args描述中给出的annotation
    @within 类型拥有@target描述中给出的annotation,其中@target和@within的区别在于@within要求的annotation的级别为CLASS,而@target为RUNTIME
    @annotation 方法拥有@annotation 描述中给出的annotation
    bean(idOrNameOfBean)  bean的名字或者为bean描述中的名字或者Id


    在使用Spring AOP中用的最多的应该是execution 形式的定义了,以下为它的定义格式: 
    Java代码  收藏代码
    1. execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)  

    带?号的即为可选的,别的必须给出. 

    以下给出一些JointPoint的例子: 
    匹配任意的公共方法 
    Java代码  收藏代码
    1. execution(public * *(..))   


    匹配任意方法名已set开头的方法 
    Java代码  收藏代码
    1. execution(* set*(..))   


    匹配任意AccountService接口中的方法 
    Java代码  收藏代码
    1. execution(* com.xyz.service.AccountService.*(..))  


    匹配任意AccountService接口中的方法 
    Java代码  收藏代码
    1. execution(* com.xyz.service.AccountService.*(..))  


    匹配任意service包中任意类型中的方法 
    Java代码  收藏代码
    1. execution(* com.xyz.service.*.*(..))   


    匹配任意service包或者service的子包中任意类型中的方法 
    Java代码  收藏代码
    1. execution(* com.xyz.service..*.*(..))   


    匹配任意service包中任意类型中的方法 
    Java代码  收藏代码
    1. within(com.xyz.service.*)  


    匹配任意service包或者service的子包中任意类型中的方法 
    Java代码  收藏代码
    1. within(com.xyz.service..*)  


    匹配任意实现了AccountService接口的Spring AOP代理对象的任意方法 
    Java代码  收藏代码
    1. this(com.xyz.service.AccountService)   


    匹配任意实现了AccountService接口的实际业务对象的任意方法 
    Java代码  收藏代码
    1. this(com.xyz.service.AccountService)   


    匹配任意一个接收一个参数,并且运行时参赛类型为Serializable的方法 
    Java代码  收藏代码
    1. args(java.io.Serializable)   


    匹配拥有@Transactional annotation类型的任意方法 
    Java代码  收藏代码
    1. @target(org.springframework.transaction.annotation.Transactional)    



    匹配拥有@Transactional annotation类型的任意方法 
    Java代码  收藏代码
    1. @within(org.springframework.transaction.annotation.Transactional)  


    匹配拥有@Transactional annotation的方法 
    Java代码  收藏代码
    1. @annotation(org.springframework.transaction.annotation.Transactional)  


    匹配任意一个接收一个参数,并且运行时参赛类型拥有@Classified annotation的方法 
    Java代码  收藏代码
    1. @args(com.xyz.security.Classified)  


    匹配bean的Id或者名字为tradeService的任意方法 
    Java代码  收藏代码
    1. bean(tradeService)  


    匹配bean的Id或者名字以Service结尾的任意方法 
    Java代码  收藏代码
    1. bean(*Service)  
     
  • 相关阅读:
    【BZOJ 4151 The Cave】
    【POJ 3080 Blue Jeans】
    【ZBH选讲·树变环】
    【ZBH选讲·拍照】
    【ZBH选讲·模数和】
    【CF Edu 28 C. Four Segments】
    【CF Edu 28 A. Curriculum Vitae】
    【CF Edu 28 B. Math Show】
    【CF Round 439 E. The Untended Antiquity】
    【CF Round 439 C. The Intriguing Obsession】
  • 原文地址:https://www.cnblogs.com/huanglin101/p/7286287.html
Copyright © 2011-2022 走看看