You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot中@Around实现AOP时切点执行但无返回结果求助

问题分析与解决方案

Hey, I totally get what's going on here! The problem lies in how you're handling the return value of your @Around advice method.

Why the browser isn't getting the response

When you use @Around advice, it's responsible for both executing the target method and passing back its return value to the caller. Your current advice method returns void, which means Spring has no idea to pass along the "Hello World" string that your controller method returns. Even though the target method runs correctly, the return value gets swallowed up by your advice.

Fix it by returning the proceed() result

All you need to do is change the return type of your advice method to Object, and return the result of proceedingJoinPoint.proceed(). Here's the corrected code:

@Around("cut()")
public Object advice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    System.out.println("@Around start");
    // Capture the return value of the target method
    Object result = proceedingJoinPoint.proceed();
    System.out.println("@Around end");
    // Return it so the caller (Spring MVC) gets it
    return result;
}

A quick note on @Around behavior

  • If your target method returns a value (like your controller's String), your @Around method must return that value (or a modified version of it) for the caller to receive it.
  • Only use a void return type for @Around if the target method itself is void—otherwise, you'll lose the return value just like you did here.

After making this change, when you hit the /log endpoint, the browser will correctly receive the "Hello World" response, and your logs will still print in the expected order!

内容的提问来源于stack exchange,提问作者Martin521Wang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:22:35