Spring framework version 5 has been released along with a new module, Spring WebFlux, with functionality that helps us build Reactive web applications. How is it in detail? In this tutorial, I will introduce you to some basic knowledge about Spring WebFlux!
The first thing you need to know is that Spring WebFlux uses Project Reactor by default to implement the Reactive framework. Project Reactor is a Reactive Streams library that we introduced to you in this tutorial. You can also use other libraries implementing Reactive Streams specification like RxJava, … to work with Spring WebFlux.
As you know, in Spring MVC the request information from the client will be held in the HttpServletRequest object and the information returned to the client will be held by the HttpServletResponse object. But for Spring WebFlux with Reactive support, the information from the request is contained in the ServerHttpRequest object, and the response information is held by the ServerHttpResponse object. The body of the request and the response instead of the InputStream and OutputStream objects, will now be the Flux <DataBuffer> object.
Applications using Spring WebFlux must be run on servlet servers that support Servlet 3.1 or higher with non-blocking I/O. In general, it should be asynchronous.
To develop Reactive web applications using Spring WebFlux, we have two ways:
- One: using Spring MVC with the @Controller and @RestController annotation.
- The other two: using Functional Programming with Routers and Handlers objects.
In some next tutorials, I will introduce you one by one.