spring-boot - @Around(AOP) 的 joinPoint 继续但不返回结果
问题描述
我使用@Around 用springboot 实现AOP。像下面
@Around("cut()")
public void advice( ProceedingJoinPoint proceedingJoinPoint ) throws Throwable {
System.out.println("@Around start");
proceedingJoinPoint.proceed();
System.out.println("@Around end");
}
joinPoint 是我的控制器 & The"@Mylog"
是我的自定义注释。如下所示
@MyLog
@RequestMapping("/log")
public String getLog() throws InterruptedException {
System.out.println("This is joinPoint");
return "Hello World";
}
当我尝试使用浏览器获取路由“/log”时,信息按预期打印,但没有任何内容返回到浏览器(我希望"Hello World"
会返回)。像下面
@Around start
This is joinPoint
@Around end
有什么建议吗?
解决方案
如果你的 around 建议没有返回任何 ( void
) 而不是proceed()
结果,那么你应该不会感到惊讶,那么实际上什么也没有返回。;-) 这个怎么样?
@Around("cut()")
public Object advice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("@Around start");
try {
return proceedingJoinPoint.proceed();
}
finally {
System.out.println("@Around end");
}
}
推荐阅读
- python - Python:如何获取函数中条目的值
- javascript - 未捕获的语法错误:意外的标记“<”
- javascript - “Array.from() 不会创建中间数组”是什么意思?
- python - 在python中缓存响应
- flutter - 滑动加载图像滞后
- r - 在 R 中添加一个包含存在/不存在信息的新列
- bash - 并排连接两个文件,附加字段之间的差异,并以表格格式打印
- sql - 不允许使用 group by 函数的 where 语句
- javascript - 将 wp_localize_script() 对象传递给 js 文件时出现 jshint 错误
- google-play - 有没有办法将 AdMob 添加到受信任的网络活动中?