【问题标题】:Spring-webflux, how to get the request as parameter in @ExceptionHandlerSpring-webflux,如何在@ExceptionHandler 中获取请求作为参数
【发布时间】:2019-02-23 19:55:21
【问题描述】:

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

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

但是,我已经尝试了经典 MVC 模型中处理程序方法的所有可能类型,但没有一个被接受(HttpServletRequestWebRequestServerRequest)。

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

【问题讨论】:

    标签: spring spring-boot exception-handling spring-webflux


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢。没想到 HttpServletRequestWebRequest 有任何结果,但认为 ServerRequest 用于功能和带注释的控制器模型。
    猜你喜欢
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 2011-07-25
    • 2020-10-17
    相关资源
    最近更新 更多