How to configure spring-boot servlet like in web.xml?

前端 未结 1 967
天涯浪人
天涯浪人 2020-12-13 07:50

I have a simple servlet configuration in web.xml:


    appServlet

        
相关标签:
1条回答
  • 2020-12-13 08:28

    If I take your question at face value (you want a SpringBootServletInitializer that duplicates your existing app) I guess it would look something like this:

    @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<String,String> params = new HashMap<String,String>();
            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;
        }
    
    }
    

    See docs on converting an existing app for more detail.

    But, rather than using Atmosphere, you are probably better off these days using the native Websocket support in Tomcat and Spring (see the websocket sample and guide for examples).

    0 讨论(0)
提交回复
热议问题