mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix Date and aopbug
This commit is contained in:
@@ -36,12 +36,13 @@ public class CglibInterceptor implements MethodInterceptor, Serializable {
|
||||
|
||||
@Override
|
||||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
|
||||
final Object target = this.target;
|
||||
Object result = null;
|
||||
|
||||
// 开始前回调
|
||||
if (aspect.before(target, method, args)) {
|
||||
try {
|
||||
result = proxy.invokeSuper(obj, args);
|
||||
// result = proxy.invokeSuper(obj, args);
|
||||
result = proxy.invoke(target, args);
|
||||
} catch (InvocationTargetException e) {
|
||||
// 异常回调(只捕获业务代码导致的异常,而非反射导致的异常)
|
||||
if (aspect.afterException(target, method, args, e.getTargetException())) {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package cn.hutool.aop.test;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.aop.ProxyUtil;
|
||||
import cn.hutool.aop.aspects.TimeIntervalAspect;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* AOP模块单元测试
|
||||
@@ -27,6 +27,7 @@ public class AopTest {
|
||||
Dog dog = ProxyUtil.proxy(new Dog(), TimeIntervalAspect.class);
|
||||
String result = dog.eat();
|
||||
Assert.assertEquals("狗吃肉", result);
|
||||
|
||||
dog.seize();
|
||||
}
|
||||
|
||||
@@ -68,4 +69,20 @@ public class AopTest {
|
||||
Console.log("抓了只鸡");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCGLIBProxy() {
|
||||
TagObj target = new TagObj();
|
||||
//目标类设置标记
|
||||
target.setTag("tag");
|
||||
|
||||
TagObj proxy = ProxyUtil.proxy(target, TimeIntervalAspect.class);
|
||||
//代理类获取标记tag (断言错误)
|
||||
Assert.assertEquals("tag", proxy.getTag());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TagObj{
|
||||
private String tag;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user