Spring aop 踩坑

今天为了测试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;
    }
结果正常了。


猜你喜欢

转载自blog.csdn.net/skymouse2002/article/details/79226623