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!
浙公网安备 33010602011771号