读书人

Spring3.1错误通知ThrowsAdvice说明

发布时间: 2012-10-24 14:15:58 作者: rapoo

Spring3.1异常通知ThrowsAdvice说明
引言:

笔者直接从Spring2.x跳到Spring3.1,在用到org.springframework.aop.ThrowsAdvice时,发现ThrowsAdvice接口内部已经被清空,立即迷茫了。怎么个说法?

正文:

遇到这样的问题,啥也别说,先找Spring3.1的官方文档瞅瞅看有没说明(要没的话3.0继续找)……

两分钟后,找到下面一段说明:

Throws adviceThrows advice is invoked after the return of the join point if the join point threw an exception. Springofferstypedthrowsadvice.Notethatthismeansthattheorg.springframework.aop.ThrowsAdvice interface does not contain any methods: It is a taginterface identifying that the given object implements one or more typed throws advice methods. Theseshould be in the form of:    afterThrowing([Method, args, target], subclassOfThrowable)Only the last argument is required. The method signatures may have either one or four arguments,depending on whether the advice method is interested in the method and arguments. ...


大意是,ThrowsAdvice不包含任何方法了,只是一个接口标志符,方便类自己选择一个或多个通知方法。简单地说放开了“必须实现XXX的限制”

这样上面引文中的“afterThrowing”参数中的方括号中的部分便可为可选部分,而最后一个参数也可以随意指定为自己想要的任何实现了“Throwable”的对象。

(结束)

读书人网 >软件架构设计

热点推荐