• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

浮尘轻扬

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

Feign调用@GetMapping 报错: HttpRequestMethodNotSupportedException: Request method 'POST' not supported

 先捕捉是哪个请求报的异常

@ControllerAdvice
@Slf4j
public class CommonExceptionHandler {


@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<ResponseVO<Void>> handleMethodNotAllowed(HttpRequestMethodNotSupportedException e, HttpServletRequest request) {

log.error("请求报错:{} {}", request.getRequestURL().toString(), request.getMethod());
log.info("请求报错:{} {}", request.getRequestURL().toString(), request.getMethod());
return handler(e, "500", e.getMessage());
}
}

 

找到原因:

Feign 默认的参数传递方式

在 Spring Cloud OpenFeign 中,默认情况下:

  • 如果方法参数是基本数据类型(如 Long、String),Feign 会自动将其作为 Request Body,并使用 POST 请求!

  • 如果想让 Feign 以 GET 方式发送参数,必须使用 @RequestParam!

posted on 2025-03-28 15:58  浮尘轻扬  阅读(130)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3