简体   繁体   English

如何在 Spring-Boot 中注册启用了“异步支持”的 servlet?

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

I'm planing to migrate my old app to Spring-Boot.我打算将我的旧应用程序迁移到 Spring-Boot。
I want to stop using web.xml descriptor and register old pure Servlet ("async-supported" enabled) and an associated ServletContextListener.我想停止使用 web.xml 描述符并注册旧的纯 Servlet(启用“异步支持”)和关联的 ServletContextListener。

Spring Boot will automatically register any Servlet beans in your application context with the servlet container. Spring Boot 会自动将应用程序上下文中的任何Servlet bean 注册到 servlet 容器。 By default async supported is set to true so there's nothing for you to do beyond creating a bean for your Servlet .默认情况下, async supported 设置为true因此除了为Servlet创建 bean 之外,您无事可做。

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 .如果出于某种原因,您想对 servlet 的注册进行更多控制,那么,与其将 Servlet 本身作为 bean 公开,您还可以将其包装在ServletRegistrationBean

Put a @EnableAsync on your application class.将 @EnableAsync 放在您的应用程序类上。 See here for more details.请参阅此处了解更多详情。

servletRegistrationBean.isAsyncSupported() is by default true which decides whether the Async functionality is supported or not. servletRegistrationBean.isAsyncSupported()默认为true ,它决定是否支持异步功能。

在此处输入图片说明 . .

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. java.lang.IllegalArgumentException:必须在 servlet 和异步请求处理中涉及的所有过滤器上启用异步支持。 This is done in Java code using the Servlet API or by adding "true" to servlet and filter declarations in web.xml.这是使用 Servlet API 在 Java 代码中完成的,或者通过向 web.xml 中的 servlet 和过滤器声明添加“true”来完成。 Also you must use a Servlet 3.0+ container您还必须使用 Servlet 3.0+ 容器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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