There are 2 different features available:
servlet 3.0 allows to process request in a thread different from the container thread.
servlet 3.1 allows to read/write into socket without blocking reading/writing thread
There are a lot of examples in the internet about servlet 3.0 feature. We can use it in Spring very easily. We just have to return DefferedResult
or CompletableFuture
But I can't find example of usage servlet 3.1 in spring. As far as I know we have to register WriteListener
and ReadListener
and do dome dirty work inside. But I can't find the example of that Listeners. I believe it is not very easy.
Could you please provide example of servlet 3.1 feature in spring with explanation of Listener implementaion ?
Yes it is. Spring-MVC uses DispatcherServlet under the hood. Central dispatcher for HTTP request handlers/controllers, e.g. for web UI controllers or HTTP-based remote service exporters.
In Spring-MVC when you write annotation like @Controller, indirectly you are using a Servlet called Dispatcher Servlet. Dispatcher Servlet is defined in web. xml file with properties and class name which is mapped to . jsp pages and Controller part.
You can also deploy Spring Boot applications to any Servlet 3.1+ compatible container.
spring-servlet. xml. In Spring, a single front servlet takes the incoming requests and delegates them to appropriate controller methods. The front servlet, based on a Front controller design pattern, handles all the HTTP requests of a particular web application.
For servlet 3.1 you can support non-blocking I/O by using Reactive Streams bridge
Servlet 3.1+ Container
To deploy as a WAR to any Servlet 3.1+ container, you can extend and include {api-spring-framework}/web/server/adapter/AbstractReactiveWebInitializer.html[AbstractReactiveWebInitializer] in the WAR. That class wraps an HttpHandler with ServletHttpHandlerAdapter and registers that as a Servlet.
So you should extend AbstractReactiveWebInitializer which is adding async support
registration.setAsyncSupported(true);
And the support in ServletHttpHandlerAdapter
AsyncContext asyncContext = request.startAsync();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With