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

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:

import org.springframework.http.server.reactive.ServletServerHttpRequest;

@RestController
public class GreetingController {

    @GetMapping("/greetings")
    public Mono<Greeting> greeting(ServerHttpRequest request) {

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

You can inject either ServerWebExchange or directly ServerHttpRequest / ServerHttpResponse.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)