我想配置Spring以便它执行的建议时,一个特定的异常子类(MyTestException
)被抛出:Spring AOP和异常拦截
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配置:
我有一种感觉,我应该使用target
切入点说明符(而不是execution
),因为 - 根据Spring docs - 看起来好像target
允许我指定异常的类型以再次匹配吨,但我不确定这是错误的,还是我的属性需要看起来像。
我会大大宁愿保持在XML完成(而不是到Java /注解的AOP配置,但如果需要的话我大概可以翻译基于注解式的解决方案为XML。