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)  
     
  • 相关阅读:
    利用递归分割(Split)字符串
    SQL Server2012 T-SQL基础教程--读书笔记(1-4章)
    kindeditor编辑器的使用
    echarts绘制四川地图
    Windows下搭建PHP开发环境(Apache+PHP+MySQL)+调试工具Xdebug的配置
    给搜索关键字添加高亮,加以颜色区分
    SQL 生成6位随机数并MD5加密输出
    微信小程序登录 .net 后端实现
    钉钉小程序http post 请求
    浅谈Web Api配合SignalR的跨域支持
  • 原文地址:https://www.cnblogs.com/huanglin101/p/7286287.html
Copyright © 2011-2022 走看看