如何在web.xml中配置spring-boot servlet?

我在web.xml中有一个简单的servlet配置:

 appServlet org.atmosphere.cpr.MeteorServlet  org.atmosphere.servlet org.springframework.web.servlet.DispatcherServlet   contextClass  org.springframework.web.context.support.AnnotationConfigWebApplicationContext    contextConfigLocation net.org.selector.animals.config.ComponentConfiguration  1 true   appServlet /  

如何为SpringBootServletInitializer重写它?

如果我从表面上看你的问题(你想要一个复制现有应用程序的SpringBootServletInitializer ),我想它看起来像这样:

 @Configuration public class Restbucks extends SpringBootServletInitializer { protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Restbucks.class, ComponentConfiguration.class); } @Bean public MeteorServlet dispatcherServlet() { return new MeteorServlet(); } @Bean public ServletRegistrationBean dispatcherServletRegistration() { ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet()); Map params = new HashMap(); params.put("org.atmosphere.servlet","org.springframework.web.servlet.DispatcherServlet"); params.put("contextClass","org.springframework.web.context.support.AnnotationConfigWebApplicationContext"); params.put("contextConfigLocation","net.org.selector.animals.config.ComponentConfiguration"); registration.setInitParameters(params); return registration; } } 

有关更多详细信息,请参阅有关转换现有应用的文档 。

但是,使用Tomcat和Spring中的本机Websocket支持(而不是使用Atmosphere),最好不要使用Tomcat和Spring中的本机Websocket支持(请参阅websocket示例和指南中的示例)。