Spring AOP中JoinPoint的表达式定义描述

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

execution方法签名需要满足execution中描述的方法签名
within包或者类型满足within中描述的包或者类型的类的所有非私有方法
thisSpring 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) 

转载地址:http://chiyx.iteye.com/blog/1568600点击打开链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值