今天为了测试hystrix做了个简单的aop功能,但是居然出现了被aop的方法结果丢失的情况,经过查证发现是返回值惹的货
先上问题代码:
@Around("execution(* com.forezp.service.AccountService.*(..))")
public void monitorAround(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("method start time:" + System.currentTimeMillis());
Object re = pjp.proceed();
System.out.println("method end time:" + System.currentTimeMillis());
}
经过debug发现如果注释掉这段代码结果正常,打开结果均为空,
修改后的代码如下:
@Around("execution(* com.forezp.service.AccountService.*(..))")
public Object monitorAround(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("method start time:" + System.currentTimeMillis());
Object re = pjp.proceed();
System.out.println("method end time:" + System.currentTimeMillis());
return re;
}
结果正常了。