点点滴滴积累——基于XMLSchema与Annotation的几种Advice的规则

1.关于before advice:
对于before advice,是最简单的advice。无论是基于XmlSchema或者是基于Annotation,其advice对应的方法的参数只有一个,即JoinPoint类型的参数。在XmlSchema中其<aop:before.../>标签中的属性为①pointcut-ref或者piointcut②method
在Annotation中,也仅有一个属性,即pointcut,且这个属性可以被省略掉。如:@Before("execution(...)")
2.关于 after-returning advice:
after-returning advice就其对应的方法而言,需要分情况讨论。当基于XmlSchema来代理时,其对应方法的参数仅有一个,即JoinPoint类型的参数。而当基于Annotation的时候,其对应方法有两个参数,一个是JoinPoint型参数,另外一个是Object类型的参数(代表返回值)。
在Xml中,其标签对应的是<aop:after-returning.../>其属性有①pointcut-ref或者pointcut②method
在Annotation中,有两个属性:pointcut与returning。如:
@AfterRteturning(pointcut="execution(...)",returning="retVal")这个retVal就是Annotation情况下Advice对应方法中代表返回值的那个Object类型参数。
3.关于after-throwing advice:
after-throwing advice就对应方法来说,不论是基于XML还是基于Annotation都是具有两个参数:JoinPoint类型参数,与代表返回异常的Throwable类型参数。在xml中,对应标签为<aop:after-returning....>标签属性除了pintcut-ref(或者pintcut)与method外,还有一个属性throwing,其值一般为throwable。
基于Annotation时,带有两个属性:pointcut与throwing。如:@AfterThrowing(pointcut="execution(...)",throwing="throwable")这个throwable就是对应Annotation里面方法中的代表抛出异常的那个参数。
这里的异常类型需要在目标对象的接口中预先定义,异常类型可以是任何异常类型。
也就是说after returning advice在基于XmlSchema的时候对应方法仅一个参数,而throw advice无论在xmlSchema或者是基于Annotation都是有两个参数。而且,第二个参数总是要在xml或者Annotation中进行显示声明。即throwing=throwable
4.关于around advice
around advice是对before advice 与afterreturning advice两者都需要插入对象时的简化。类似before advice ,比较简单,这里不在赘述
另外,使用Annotation,需要引入aspectjweaver.jar

转载于:https://my.oschina.net/u/856612/blog/85948

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值