简体   繁体   中英

How to register a servlet with enabled "async-supported" in Spring-Boot?

I'm planing to migrate my old app to Spring-Boot.
I want to stop using web.xml descriptor and register old pure Servlet ("async-supported" enabled) and an associated ServletContextListener.

Spring Boot will automatically register any Servlet beans in your application context with the servlet container. By default async supported is set to true so there's nothing for you to do beyond creating a bean for your Servlet .

If, for whatever reason, you want to take more control over your servlet's registration, then, rather than exposing the Servlet itself as a bean, you can wrap it in a ServletRegistrationBean .

Put a @EnableAsync on your application class. See here for more details.

servletRegistrationBean.isAsyncSupported() is by default true which decides whether the Async functionality is supported or not.

在此处输入图片说明 .

If you are facing below issue then follow the link

java.lang.IllegalArgumentException: Async support must be enabled on a servlet and for all filters involved in async request processing. This is done in Java code using the Servlet API or by adding "true" to servlet and filter declarations in web.xml. Also you must use a Servlet 3.0+ container

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM