当@Around 用于 Spring AOP 时,不会检索数据
when @Around is used for Spring AOP then data is not retrieved
我是spring AOP,我有如下@Around
@Around(value = "execution(* com.spring.rest.controller.Controller.*(..))")
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
joinPoint.proceed();
long taken = System.currentTimeMillis() - start;
logger.info("around this {} time taken is {}", joinPoint, taken);
}
在我的 Rest 控制器中,我有 getmapping,当我在浏览器中调用该路由时 没有检索到数据。
从日志中,我发现它返回了 null(在日志信息下方)--
@Around被执行,耗时20秒,@AfterReturning被执行,返回null
2020-05-07 00:41:03.083 INFO 366372 --- [nio-8080-exec-1] lication$$EnhancerBySpringCGLIB$c1be2 : around this execution(List com.spring.rest.controller.Controller.getm()) time taken is 20
2020-05-07 00:41:03.084 INFO 366372 --- [nio-8080-exec-1] lication$$EnhancerBySpringCGLIB$c1be2 : returning execution(List com.spring.rest.controller.Controller.getm()) returned with value null
但是当我删除@Around 时,API 工作正常。
我能知道可能是什么原因以及如何解决这个问题吗?
您需要return对象。
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object object = joinPoint.proceed();
long taken = System.currentTimeMillis() - start;
logger.info("around this {} time taken is {}", joinPoint, taken);
return object;
}
我是spring AOP,我有如下@Around
@Around(value = "execution(* com.spring.rest.controller.Controller.*(..))")
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
joinPoint.proceed();
long taken = System.currentTimeMillis() - start;
logger.info("around this {} time taken is {}", joinPoint, taken);
}
在我的 Rest 控制器中,我有 getmapping,当我在浏览器中调用该路由时 没有检索到数据。
从日志中,我发现它返回了 null(在日志信息下方)-- @Around被执行,耗时20秒,@AfterReturning被执行,返回null
2020-05-07 00:41:03.083 INFO 366372 --- [nio-8080-exec-1] lication$$EnhancerBySpringCGLIB$c1be2 : around this execution(List com.spring.rest.controller.Controller.getm()) time taken is 20
2020-05-07 00:41:03.084 INFO 366372 --- [nio-8080-exec-1] lication$$EnhancerBySpringCGLIB$c1be2 : returning execution(List com.spring.rest.controller.Controller.getm()) returned with value null
但是当我删除@Around 时,API 工作正常。
我能知道可能是什么原因以及如何解决这个问题吗?
您需要return对象。
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object object = joinPoint.proceed();
long taken = System.currentTimeMillis() - start;
logger.info("around this {} time taken is {}", joinPoint, taken);
return object;
}