我正在尝试配置Spring,以便在抛出特定异常子类(MyTestException
)时执行通知:
public class MyTestExceptionInterceptor implements ThrowsAdvice {
public void afterThrowing(Method method, Object[] args, Object target, Exception exc) {
// I want this to get executed every time a MyTestException is thrown,
// regardless of the package/class/method that is throwing it.
}
}
以下是XML配置文件:
<bean name="interceptor" class="org.me.myproject.MyTestExceptionInterceptor"/>
<aop:config>
<aop:advisor advice-ref="interceptor" pointcut="execution(???)"/>
</aop:config>
我有一种感觉,应该使用
target
切入点指示器(而不是execution
),因为根据Spring文档的说法,似乎target
允许我指定要匹配的异常类型,但我不确定是否正确,或者我的pointcut
属性需要看起来像什么。我非常希望在XML中完成AOP配置(而不是Java /注释),但如果需要,我可能可以将基于注释的解决方案转换为XML。