Blame view

src/main/java/fr/plil/sio/web/mvc/WebAppInitializer.java 1.47 KB
aa193b2b   Julien Iguchi-Cartigny   First version
1
2
3
4
5
  package fr.plil.sio.web.mvc;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRegistration;
5e965ce4   Julien Iguchi-Cartigny   working version
6
7
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
aa193b2b   Julien Iguchi-Cartigny   First version
8
  import org.springframework.web.WebApplicationInitializer;
aa193b2b   Julien Iguchi-Cartigny   First version
9
10
  import org.springframework.web.context.ContextLoaderListener;
  import org.springframework.web.context.WebApplicationContext;
5e965ce4   Julien Iguchi-Cartigny   working version
11
12
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
aa193b2b   Julien Iguchi-Cartigny   First version
13
14
  
  public class WebAppInitializer implements WebApplicationInitializer {
5e965ce4   Julien Iguchi-Cartigny   working version
15
16
17
      
      private static final Logger logger = LoggerFactory.getLogger(WebAppInitializer.class);    
      
aa193b2b   Julien Iguchi-Cartigny   First version
18
19
      @Override
      public void onStartup(ServletContext servletContext) throws ServletException {
5e965ce4   Julien Iguchi-Cartigny   working version
20
          logger.info("starting web app initializer");
aa193b2b   Julien Iguchi-Cartigny   First version
21
22
          WebApplicationContext context = getContext();
          servletContext.addListener(new ContextLoaderListener(context));
5e965ce4   Julien Iguchi-Cartigny   working version
23
24
          ServletRegistration.Dynamic dispatcher = servletContext
                  .addServlet("dispatcher", new DispatcherServlet(context));
aa193b2b   Julien Iguchi-Cartigny   First version
25
          dispatcher.setLoadOnStartup(1);
5e965ce4   Julien Iguchi-Cartigny   working version
26
          dispatcher.addMapping("/");
aa193b2b   Julien Iguchi-Cartigny   First version
27
      }
5e965ce4   Julien Iguchi-Cartigny   working version
28
      
aa193b2b   Julien Iguchi-Cartigny   First version
29
      private AnnotationConfigWebApplicationContext getContext() {
5e965ce4   Julien Iguchi-Cartigny   working version
30
          logger.info("start web application context");
aa193b2b   Julien Iguchi-Cartigny   First version
31
32
33
34
35
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.register(WebAppConfig.class);
          return context;
      }
  }