Comment configurer un servlet Spring-Boot comme dans web.xml?

J’ai une configuration de servlet simple dans web.xml:

 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 /  

Comment puis-je le réécrire pour SpringBootServletInitializer?

Si je prends votre question à sa valeur nominale (vous voulez un SpringBootServletInitializer qui duplique votre application existante), je suppose que cela ressemblerait à ceci:

 @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; } } 

Consultez la documentation sur la conversion d’une application existante pour plus de détails.

Mais, plutôt que d’utiliser Atmosphere, il est probablement préférable d’utiliser le support Websocket natif dans Tomcat et Spring (voir l’ exemple et le guide de Websocket pour des exemples).