博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AOP JoinPoint
阅读量:4660 次
发布时间:2019-06-09

本文共 2196 字,大约阅读时间需要 7 分钟。

在使用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)  
 

转载于:https://www.cnblogs.com/huanglin101/p/7286287.html

你可能感兴趣的文章
java_js_避免无意义的条件判断
查看>>
Java并发程序设计(一) 基础概念
查看>>
Linux命令date日期时间和Unix时间戳互转
查看>>
LightOJ - 1297 Largest Box LightOJ(一元三次方程求极大值)
查看>>
883H - Palindromic Cut(思维+STL)
查看>>
.NET FTP上传文件
查看>>
操作系统中的调度算法
查看>>
JVM方法调用栈
查看>>
目标跟踪之Lukas-Kanade光流法
查看>>
python基础(第二课)
查看>>
C语言预处理条件语句的 与或运算
查看>>
D1图论最短路专题
查看>>
.Net core的日志系统
查看>>
shell脚本颜色的设置
查看>>
2019春总结作业
查看>>
小程序数据绑定的拓展用法
查看>>
DRF 版本 认证
查看>>
MVC 4将jQuery升级到1.9出现各种问题。。。
查看>>
JedisPool资源池优化
查看>>
第2次作业+105032014140
查看>>