/**
   * A Molgenis common web application initializer
   *
   * @param servletContext
   * @param appConfig
   * @param isDasUsed is the molgenis-omx-das module used?
   * @throws ServletException
   */
  protected void onStartup(ServletContext servletContext, Class<?> appConfig, boolean isDasUsed)
      throws ServletException {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(appConfig);

    // Manage the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcherServlet =
        servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    if (dispatcherServlet == null) {
      logger.warn(
          "ServletContext already contains a complete ServletRegistration for servlet 'dispatcher'");
    } else {
      final int maxSize = 32 * 1024 * 1024;
      int loadOnStartup = (isDasUsed ? 2 : 1);
      dispatcherServlet.setLoadOnStartup(loadOnStartup);
      dispatcherServlet.addMapping("/");
      dispatcherServlet.setMultipartConfig(
          new MultipartConfigElement(null, maxSize, maxSize, maxSize));
      dispatcherServlet.setInitParameter("dispatchOptionsRequest", "true");
    }

    // add filters
    javax.servlet.FilterRegistration.Dynamic etagFilter =
        servletContext.addFilter("etagFilter", new ShallowEtagHeaderFilter());
    etagFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "dispatcher");

    // enable use of request scoped beans in FrontController
    servletContext.addListener(new RequestContextListener());
  }
  public static void defaultSetup(
      ServletContext servletContext, WebApplicationContext rootContext) {

    //
    //        // Manage the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.addListener(new RequestContextListener());

    // !!! Force UTF8 encoding !!!
    {
      FilterRegistration.Dynamic fr =
          servletContext.addFilter("CharacterEncodingFilter", new CharacterEncodingFilter());
      fr.setInitParameter("encoding", "UTF-8");
      fr.setInitParameter("forceEncoding", "true");
      fr.addMappingForUrlPatterns(null, true, "/*");
      fr.setAsyncSupported(true);
    }

    {
      FilterRegistration.Dynamic fr = servletContext.addFilter("CorsFilter", new CorsFilter());
      fr.addMappingForUrlPatterns(null, true, "/*");
      fr.setAsyncSupported(true);
      //  fr.setInitParameter("dispatcher", "REQUEST");
    }

    {
      FilterRegistration.Dynamic fr = servletContext.addFilter("FilterPost", new FilterPost());
      fr.addMappingForUrlPatterns(null, true, "/*");
      fr.setAsyncSupported(true);
      //  fr.setInitParameter("dispatcher", "REQUEST");
    }
  }
 @Override
 public void onStartup(ServletContext servletContext) throws ServletException {
   WebApplicationContext context = getContext();
   ServletRegistration.Dynamic dispatcher =
       servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
   dispatcher.setLoadOnStartup(1);
   dispatcher.addMapping("/secure/*");
   servletContext.addListener(new SpartanLogManagerLoader());
   servletContext.addListener(new ContextLoaderListener(context));
   servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
 }
Example #4
0
  @Override
  public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
    ctx.addServlet(ConfigurationServlet.class.getSimpleName(), new ConfigurationServlet())
        .addMapping(ConfigurationServlet.CONFIGURATION_ENDPOINT);
    ctx.addServlet(
            StagemonitorMetricsServlet.class.getSimpleName(), new StagemonitorMetricsServlet())
        .addMapping("/stagemonitor/metrics");
    ctx.addServlet(RumServlet.class.getSimpleName(), new RumServlet())
        .addMapping("/stagemonitor/public/rum");
    ctx.addServlet(FileServlet.class.getSimpleName(), new FileServlet())
        .addMapping("/stagemonitor/static/*", "/stagemonitor/public/static/*");
    ctx.addServlet(WidgetServlet.class.getSimpleName(), new WidgetServlet())
        .addMapping("/stagemonitor");

    final ServletRegistration.Dynamic requestTraceServlet =
        ctx.addServlet(RequestTraceServlet.class.getSimpleName(), new RequestTraceServlet());
    requestTraceServlet.addMapping("/stagemonitor/request-traces");
    requestTraceServlet.setAsyncSupported(true);

    final FilterRegistration.Dynamic securityFilter =
        ctx.addFilter(
            StagemonitorSecurityFilter.class.getSimpleName(), new StagemonitorSecurityFilter());
    // Add as last filter so that other filters have the chance to set the
    // WebPlugin.STAGEMONITOR_SHOW_WIDGET request attribute that overrides the widget visibility.
    // That way the application can decide whether a particular user is allowed to see the widget.P
    securityFilter.addMappingForUrlPatterns(
        EnumSet.of(DispatcherType.REQUEST), true, "/stagemonitor/*");
    securityFilter.setAsyncSupported(true);

    final FilterRegistration.Dynamic monitorFilter =
        ctx.addFilter(
            HttpRequestMonitorFilter.class.getSimpleName(), new HttpRequestMonitorFilter());
    monitorFilter.addMappingForUrlPatterns(
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
    monitorFilter.setAsyncSupported(true);

    final FilterRegistration.Dynamic userFilter =
        ctx.addFilter(UserNameFilter.class.getSimpleName(), new UserNameFilter());
    // Have this filter run last because user information may be populated by other filters e.g.
    // Spring Security
    userFilter.addMappingForUrlPatterns(
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");
    userFilter.setAsyncSupported(true);

    ctx.addListener(MDCListener.class);
    ctx.addListener(MonitoredHttpRequest.StagemonitorServletContextListener.class);
    ctx.addListener(SpringMonitoredHttpRequest.HandlerMappingServletContextListener.class);
    ctx.addListener(SessionCounter.class);
  }
  //	@Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
    System.out.println("##################################################");

    if (rootAppContext != null) {

      servletContext.addFilter("app", "org.apache.tapestry5.TapestryFilter");

      servletContext.setInitParameter("tapestry.app-package", "com.noofinc");
      FilterRegistration.Dynamic tapestryFilter =
          servletContext.addFilter("app", new TapestryFilter());
      tapestryFilter.addMappingForUrlPatterns(null, true, "/*");
      tapestryFilter.setAsyncSupported(true);

      servletContext.addListener(
          new ContextLoaderListener(rootAppContext) {
            @Override
            public void contextInitialized(ServletContextEvent event) {
              // no-op because the application context is already initialized
            }
          });
    } else {
      this.logger.debug(
          "No ContextLoaderListener registered, as "
              + "createRootApplicationContext() did not "
              + "return an application context");
    }
  }
  /**
   * Register and configure all Servlet container components necessary to power the web application.
   */
  @Override
  public void onStartup(final ServletContext sc) throws ServletException {
    System.out.println("MyWebAppInitializer.onStartup()");

    // Create the 'root' Spring application context
    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.scan("org.baeldung.config.parent");
    // root.getEnvironment().setDefaultProfiles("embedded");

    // Manages the lifecycle of the root application context
    sc.addListener(new ContextLoaderListener(root));

    // Handles requests into the application
    final AnnotationConfigWebApplicationContext childWebApplicationContext =
        new AnnotationConfigWebApplicationContext();
    childWebApplicationContext.scan("org.baeldung.config.child");
    final ServletRegistration.Dynamic appServlet =
        sc.addServlet("api", new DispatcherServlet(childWebApplicationContext));
    appServlet.setLoadOnStartup(1);
    final Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
      throw new IllegalStateException(
          "'appServlet' could not be mapped to '/' due "
              + "to an existing mapping. This is a known issue under Tomcat versions "
              + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
    }

    // spring security filter
    final DelegatingFilterProxy springSecurityFilterChain =
        new DelegatingFilterProxy("springSecurityFilterChain");
    final Dynamic addedFilter =
        sc.addFilter("springSecurityFilterChain", springSecurityFilterChain);
    addedFilter.addMappingForUrlPatterns(null, false, "/*");
  }
  @Override
  public void onStartup(final ServletContext servletContext) throws ServletException {
    try {
      // Force the timezone of application to UTC (required for Hibernate/JDBC)
      TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

      final Context initialContext = new InitialContext();

      final String logLocation =
          (String)
              initialContext.lookup("java:comp/env/osp/osgpAdapterDomainPublicLighting/log-config");
      LogbackConfigurer.initLogging(logLocation);

      final AnnotationConfigWebApplicationContext rootContext =
          new AnnotationConfigWebApplicationContext();
      rootContext.register(ApplicationContext.class);

      servletContext.addListener(new ContextLoaderListener(rootContext));

    } catch (final NamingException e) {
      throw new ServletException("naming exception", e);
    } catch (final FileNotFoundException e) {
      throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
      throw new ServletException("Logback exception", e);
    }
  }
Example #8
0
  @Override
  public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.register(SecurityConfig.class);
    container.addListener(new ContextLoaderListener(ctx));

    container
        .addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
        .addMappingForUrlPatterns(null, false, "/*");
    Map<String, String> initParams = new HashMap<String, String>();
    initParams.put("encoding", "UTF-8");
    initParams.put("forceEncoding", "true");
    FilterRegistration.Dynamic ceFilter =
        container.addFilter("encodingFilter", CharacterEncodingFilter.class);
    ceFilter.setInitParameters(initParams);
    ceFilter.addMappingForUrlPatterns(null, false, "/*");

    ctx.setServletContext(container);

    ServletRegistration.Dynamic servlet =
        container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
  }
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    //        rootContext.register(WebConfig.class);
    rootContext.scan("org.saiku.admin.config");

    ServletRegistration.Dynamic dispatcher =
        servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/*");

    servletContext.addListener(new ContextLoaderListener(rootContext));

    //        FilterRegistration.Dynamic fr = servletContext.addFilter("encodingFilter",  new
    // CharacterEncodingFilter());
    //        fr.setInitParameter("encoding", "UTF-8");
    //        fr.setInitParameter("forceEncoding", "true");
    //        fr.addMappingForUrlPatterns(null, true, "/*");

    //        FilterRegistration.Dynamic fr = servletContext.addFilter("authFilter", new
    // AuthFilter());
    //        fr.addMappingForUrlPatterns(null, true, "/*");
    //
    //        fr = servletContext.addFilter("requestsLoggerServletFilter", new
    // RequestsLoggerServletFilter());
    //        fr.addMappingForUrlPatterns(null, true, "/*");
    //
    //        fr = servletContext.addFilter("TeeFilter", new
    // ch.qos.logback.access.servlet.TeeFilter());
    //        fr.addMappingForUrlPatterns(null, true, "/*");
  }
 public void onStartup(ServletContext servletContext) throws ServletException {
   WebApplicationContext context = getContext();
   servletContext.addListener(new ContextLoaderListener(context));
   ServletRegistration.Dynamic dispatcher =
       servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
   dispatcher.setLoadOnStartup(1);
   dispatcher.addMapping("/");
 }
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    super.onStartup(servletContext);
    registerProxyFilter(servletContext, "oauth2ClientContextFilter");
    registerHiddenFieldFilter(servletContext);

    logger.debug("CAS - single sign out - adding SingleSignOutHttpSessionListener");
    servletContext.addListener(new SingleSignOutHttpSessionListener());
  }
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ServletRegistration.Dynamic servlet =
        servletContext.addServlet(DISPATCHER, new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
  }
Example #13
0
 @Override
 public void onStartup(ServletContext servletContext) throws ServletException {
   WebApplicationContext context = getContext();
   servletContext.addListener(new ContextLoaderListener(context));
   ServletRegistration.Dynamic dispatcher =
       servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
   dispatcher.setLoadOnStartup(1);
   dispatcher.addMapping(MAPPING_URL);
   dispatcher.setAsyncSupported(true);
 }
Example #14
0
 @Override
 public void onStartup(Set<Class<?>> classes, ServletContext context) throws ServletException {
   log.info("Initialize Weld using ServletContainerInitializer");
   lifecycle = new WeldServletLifecycle();
   lifecycle.initialize(context);
   context.setAttribute(WeldServletLifecycle.INSTANCE_ATTRIBUTE_NAME, lifecycle);
   context.setAttribute(
       WeldServletLifecycle.LISTENER_CLASS_FLAG_ATTRIBUTE_NAME, this.getClass().getName());
   context.addListener(this);
   super.contextInitialized(new ServletContextEvent(context));
 }
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(WebConfig.class);

    ServletRegistration.Dynamic dispatcher =
        servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/*");
    servletContext.addListener(new ContextLoaderListener(rootContext));
  }
Example #16
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(MvcConfiguration.class);

    servletContext.addListener(new ContextLoaderListener(context));
    servletContext.addListener(
        new HttpSessionListener() {
          @Override
          public void sessionCreated(HttpSessionEvent httpSessionEvent) {}

          @Override
          public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
            System.out.println("Session destroyed.");
            // TODO: Add this back in before deployment
            LoginInfo loginInfo =
                (LoginInfo) httpSessionEvent.getSession().getAttribute("loginInfo");
            if (loginInfo != null) {
              RestTemplate restTemplate = new RestTemplate();
              String url = "https://canvas.instructure.com/login/oauth2/token";
              HttpHeaders headers = new HttpHeaders();
              if (loginInfo.getAccessToken() != null) {
                headers.set("Authorization", "Bearer " + loginInfo.getAccessToken());
                HttpEntity requestEntity = new HttpEntity(headers);
                restTemplate.exchange(
                    url,
                    HttpMethod.DELETE,
                    requestEntity,
                    Object.class,
                    new HashMap<String, String>());
              }
            }
          }
        });

    ServletRegistration.Dynamic dispatcher =
        servletContext.addServlet("dispatcher", new DispatcherServlet(context));

    dispatcher.addMapping("/");
    dispatcher.setLoadOnStartup(1);
  }
 /* (non-Javadoc)
  * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
  */
 public final void onStartup(ServletContext servletContext) throws ServletException {
   if (contextLoaderListenerInitializer != null) {
     contextLoaderListenerInitializer.onStartup(servletContext);
   }
   if (enableHttpSessionEventPublisher()) {
     servletContext.addListener(
         "org.springframework.security.web.session.HttpSessionEventPublisher");
   }
   servletContext.setSessionTrackingModes(getSessionTrackingModes());
   insertSpringSecurityFilterChain(servletContext);
   afterSpringSecurityFilterChain(servletContext);
 }
Example #18
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("com.sms.config");

    // 加入logback监听器
    servletContext.addListener(new LogbackConfigListener());

    // 加入spring监听器
    servletContext.addListener(new ContextLoaderListener(context));

    EnumSet<DispatcherType> dispatcherTypes =
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    // 加入spring mvc配置
    ServletRegistration.Dynamic dispatcher =
        servletContext.addServlet("spring-mvc", new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");

    // 加入OpenEntityManagerInViewFilter
    FilterRegistration.Dynamic openEntityManagerInViewFilter =
        servletContext.addFilter(
            "openEntityManagerInViewFilter", OpenEntityManagerInViewFilter.class);
    openEntityManagerInViewFilter.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    // 加入security过滤器
    FilterRegistration.Dynamic securityFilterChain =
        servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
    securityFilterChain.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    // 加入Spring编码过滤器
    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    FilterRegistration.Dynamic encodingFilter =
        servletContext.addFilter("characterEncodingFilter", characterEncodingFilter);
    encodingFilter.addMappingForUrlPatterns(dispatcherTypes, true, "/");
  }
 @Override
 public void onStartup(ServletContext servletContext) throws ServletException {
   if (!isEnabled()) {
     logger.info("Listener " + this.listener + " was not registered (disabled)");
     return;
   }
   try {
     servletContext.addListener(this.listener);
   } catch (RuntimeException ex) {
     throw new IllegalStateException(
         "Failed to add listener '" + this.listener + "' to servlet context", ex);
   }
 }
 /**
  * Register a {@link ContextLoaderListener} against the given servlet context. The {@code
  * ContextLoaderListener} is initialized with the application context returned from the {@link
  * #createRootApplicationContext()} template method.
  *
  * @param servletContext the servlet context to register the listener against
  */
 protected void registerContextLoaderListener(ServletContext servletContext) {
   WebApplicationContext rootAppContext = createRootApplicationContext();
   mylog.debug("创建WebApplicationContext,如果不为空并注册ContextLoaderListener");
   if (rootAppContext != null) {
     ContextLoaderListener listener = new ContextLoaderListener(rootAppContext);
     listener.setContextInitializers(getRootApplicationContextInitializers());
     servletContext.addListener(listener);
   } else {
     logger.debug(
         "No ContextLoaderListener registered, as "
             + "createRootApplicationContext() did not return an application context");
   }
 }
  @Override
  public void onStartup(ServletContext ctx) throws ServletException {
    // Register the ContextLoaderListener
    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.register(DistanceConfiguration.class);

    ctx.addListener(new ContextLoaderListener(appContext));

    // Register the Servlet
    ServletRegistration.Dynamic registration = ctx.addServlet("distance", new DistanceServlet());
    registration.setLoadOnStartup(1);
    registration.addMapping("/distance");
  }
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebAppConfig.class);
    ctx.register(SecurityConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    Dynamic servlet =
        servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
  }
Example #23
0
  /**
   * HttpSessionEventPublisher listenert letrehozzuk, mivel kelleni fog a belepeshez, ha egyszerre
   * csak 1 user lehet 1 tokennel 1 sessionben
   */
  @Override
  protected void registerContextLoaderListener(ServletContext servletContext) {
    HttpSessionEventPublisher httpSessionEventPublisher = new HttpSessionEventPublisher();
    servletContext.addListener(httpSessionEventPublisher);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);
    servletContext
        .addFilter("characterEncodingFilter", characterEncodingFilter)
        .addMappingForUrlPatterns(null, false, "/*");

    super.registerContextLoaderListener(servletContext);
  }
Example #24
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.getEnvironment().setActiveProfiles("dev");
    ctx.register(WebAppConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    registerHiddenHttpMethodFilter(servletContext);

    Dynamic servlet =
        servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
  }
  @Override
  public void onStartup(ServletContext container) throws ServletException {
    container.getServletRegistration("default").addMapping("/resources/*");

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(RootContextConfiguration.class);
    container.addListener(new ContextLoaderListener(rootContext));

    AnnotationConfigWebApplicationContext servletContext =
        new AnnotationConfigWebApplicationContext();
    servletContext.register(ServletContextConfiguration.class);
    ServletRegistration.Dynamic dispatcher =
        container.addServlet("springDispatcher", new DispatcherServlet(servletContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }
Example #26
0
  public void onStartup(ServletContext container) throws javax.servlet.ServletException {
    AnnotationConfigWebApplicationContext applContext = new AnnotationConfigWebApplicationContext();
    applContext.register(Config.class);

    container.addListener(new ContextLoaderListener(applContext));

    FilterRegistration.Dynamic characterEncodingFilter =
        container.addFilter("characterEncodingFilter", new CharacterEncodingFilter());
    characterEncodingFilter.addMappingForUrlPatterns(
        EnumSet.allOf(DispatcherType.class), true, "/*");
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");

    ServletRegistration.Dynamic dispatcher =
        container.addServlet("dispatcher", new DispatcherServlet(applContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }
 @Override
 public void onStartup(ServletContext servletContext) throws ServletException {
   WebApplicationContext rootAppContext = this.createRootApplicationContext(servletContext);
   if (rootAppContext != null) {
     servletContext.addListener(
         new ContextLoaderListener(rootAppContext) {
           @Override
           public void contextInitialized(ServletContextEvent event) {
             // no-op because the application context is already initialized
           }
         });
   } else {
     this.logger.debug(
         "No ContextLoaderListener registered, as "
             + "createRootApplicationContext() did not "
             + "return an application context");
   }
 }
  @Override
  public void onStartup(ServletContext cs) {

    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(SpringRootConfig.class);
    // Manage the lifecycle of the root application context
    cs.addListener(new ContextLoaderListener(rootContext));

    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherServlet =
        new AnnotationConfigWebApplicationContext();
    dispatcherServlet.register(MvcConfig.class);

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher =
        cs.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();

    rootContext.register(ApplicationConfig.class);

    servletContext.addListener(new ContextLoaderListener(rootContext));

    AnnotationConfigWebApplicationContext dispatcherContext =
        new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(WebConfig.class);

    ServletRegistration.Dynamic dispatcher =
        servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");

    FilterRegistration.Dynamic hiddenHttpMethodFilter =
        servletContext.addFilter("hiddenHttpMethodFilter", HiddenHttpMethodFilter.class);
    hiddenHttpMethodFilter.addMappingForUrlPatterns(null, false, "/*");
  }
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();

    // Déclaration du la classe de configuration du context (dataSource, repositories,
    // spring-security ...)
    rootContext.register(ContextConfig.class);

    servletContext.addListener(new ContextLoaderListener(rootContext));

    // Création du distapcher de servlet
    AnnotationConfigWebApplicationContext dispatcherServlet =
        new AnnotationConfigWebApplicationContext();
    dispatcherServlet.register(WebMvcConfig.class);

    // Déclaration du distapcher de servlet
    ServletRegistration.Dynamic dispatcher =
        servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }