Dexter Dexter - 1 year ago 175
Java Question

Reactive Spring does not support HttpServletRequest as parameter in REST endpoint?

I created a RestController which look like this :

public class GreetingController {

@RequestMapping(value = "/greetings", method = RequestMethod.GET)
public Mono<Greeting> greeting(HttpServletRequest request) {

return Mono.just(new Greeting("Hello..." + request.toString()));

Unfortunately when I try to hit the "greetings" endpoint I get an exception :

java.lang.IllegalStateException: No resolver for argument [0] of type

I am using


How to fix this ?

Link to full stack-trace. Link to build.gradle


Using the interface. Now getting :

java.lang.IllegalStateException: No resolver for argument [0] of type
[javax.servlet.http.HttpServletRequest] on method (rest is same)

Answer Source

You should never use the Servlet API in a Spring Reactive Web application. This is not supported and this is making your app container-dependent, whereas Spring Web Reactive can work with non-Servlet runtimes such as Netty.

Instead you should use the HTTP API provided by Spring; here's your code sample with a few changes:

public class GreetingController {

    public Mono<Greeting> greeting(ServerHttpRequest request) {

        return Mono.just(new Greeting("Hello..." + request.getURI().toString()));

You can inject either ServerWebExchange or directly ServerHttpRequest / ServerHttpResponse.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download