mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复aop的afterException无法生效问题
This commit is contained in:
parent
bc30ecc3ef
commit
3fdfe356bd
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.extra.aop.engine.spring;
|
package org.dromara.hutool.extra.aop.engine.spring;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.exception.ExceptionUtil;
|
||||||
import org.dromara.hutool.extra.aop.Aspect;
|
import org.dromara.hutool.extra.aop.Aspect;
|
||||||
import org.dromara.hutool.extra.aop.SimpleInterceptor;
|
import org.dromara.hutool.extra.aop.SimpleInterceptor;
|
||||||
import org.springframework.cglib.proxy.MethodInterceptor;
|
import org.springframework.cglib.proxy.MethodInterceptor;
|
||||||
@ -47,10 +48,15 @@ public class SpringCglibInterceptor extends SimpleInterceptor implements MethodI
|
|||||||
if (aspect.before(target, method, args)) {
|
if (aspect.before(target, method, args)) {
|
||||||
try {
|
try {
|
||||||
result = proxy.invoke(target, args);
|
result = proxy.invoke(target, args);
|
||||||
} catch (final 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())) {
|
if (aspect.afterException(target, method, args, throwable)) {
|
||||||
throw e;
|
throw throwable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user