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

Viewed 4375

With spring webflux and the @RestController model, I have a @RestControllerAdvice with some @ExceptionHandler methods.

I would like to get the original request as parameter because I want to log it and use it in my response.

However I have tried all the possible types for an handler method in the classic MVC model but none of them was accepted (HttpServletRequest, WebRequest and ServerRequest).

What type can I use to access the original request in a webflux annotated handler method ?

1 Answers

You should use org.springframework.http.server.reactive.ServerHttpRequest, because:

  • HttpServletRequest and WebRequest are Servlet/Spring MVC specific
  • ServerRequest belongs to Spring WebFlux, but the functional variant
Related