如何注册启用了“异步支持"的 servlet在 Spring-Boot 中? [英] How to register a servlet with enabled "async-supported" in Spring-Boot?
问题描述
我打算将我的旧应用迁移到 Spring-Boot.
我想停止使用 web.xml 描述符并注册旧的纯 Servlet(启用异步支持")和关联的 ServletContextListener.
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 将使用 servlet 容器自动在您的应用程序上下文中注册任何 Servlet
bean.默认情况下,支持的异步设置为 true
,因此除了为 Servlet
创建一个 bean 之外,您无事可做.
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
.
如果,无论出于何种原因,您想对 servlet 的注册进行更多控制,那么,与其将 Servlet 本身作为 bean 公开,您还可以将其包装在 ServletRegistrationBean
中.
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在 Spring-Boot 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!