How to enable async support for spring MVC application in java configuration file (Not XML)

I know how to enable async support in the XML configuration, I did this for filters and servlets by adding a tag

async-supported>true/async-supported 

How to do this in the Java configuration file. I am creating a WebInit class that implements WebApplicationInitializer and overrides onStartUp - what should I do next?

 public class WebInit implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) throws ServletException { //What to do here, to move from XML to java config } } 
+6
source share
1 answer

In the following lines -

 ServletRegistration.Dynamic registration = container.addServlet(servletName, myServlet); registration.setAsyncSupported(true); 

EDIT: Sorry, didn't realize you were looking for a specific Spring solution. With Spring MVC, you simply extend AbstractAnnotationConfigDispatcherServletInitializer , assuming your root and web contexts are based on @Configuration . This initializer, in turn, extends from AbstractDispatcherServletInitializer , this class has the asyncSupported flag set by default.

+3
source

Source: https://habr.com/ru/post/975250/


All Articles