修复aop的afterException无法生效问题

This commit is contained in:
Looly
2023-10-12 21:00:33 +08:00
parent 5d8a411453
commit 7d3527bc3f
3 changed files with 16 additions and 6 deletions

View File

@@ -43,10 +43,14 @@ public class CglibInterceptor implements MethodInterceptor, Serializable {
try {
// result = proxy.invokeSuper(obj, args);
result = proxy.invoke(target, args);
} catch (InvocationTargetException e) {
} catch (final Throwable e) {
Throwable throwable = e;
if(throwable instanceof InvocationTargetException){
throwable = ((InvocationTargetException) throwable).getTargetException();
}
// 异常回调(只捕获业务代码导致的异常,而非反射导致的异常)
if (aspect.afterException(target, method, args, e.getTargetException())) {
throw e;
if (aspect.afterException(target, method, args, throwable)) {
throw throwable;
}
}
}

View File

@@ -48,9 +48,14 @@ public class SpringCglibInterceptor implements MethodInterceptor, Serializable {
try {
// result = proxy.invokeSuper(obj, args);
result = proxy.invoke(target, args);
} catch (InvocationTargetException e) {
} catch (Throwable e) {
Throwable throwable = e;
if(throwable instanceof InvocationTargetException){
throwable = ((InvocationTargetException) throwable).getTargetException();
}
// 异常回调(只捕获业务代码导致的异常,而非反射导致的异常)
if (aspect.afterException(target, method, args, e.getTargetException())) {
if (aspect.afterException(target, method, args, throwable)) {
throw e;
}
}