Spring-webflux,如何在@ExceptionHandler中获取请求作为参数

Spring-webflux, how to get the request as parameter in @ExceptionHandler

使用 spring webflux 和 @RestController 模型,我有一个 @RestControllerAdvice 和一些 @ExceptionHandler 方法。

我想获取原始请求作为参数,因为我想记录它并在我的响应中使用它。

然而,我已经尝试了经典 MVC 模型中处理程序方法的所有可能类型,但其中 none 被接受(HttpServletRequestWebRequestServerRequest ).

在 webflux 注释处理程序方法中,我可以使用什么类型来访问原始请求?

您应该使用 org.springframework.http.server.reactive.ServerHttpRequest,因为:

  • HttpServletRequestWebRequest 是 Servlet/Spring MVC 特定的
  • ServerRequest 属于 Spring WebFlux,但功能变体