Пример #1
0
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    log.info("Web application configuration");

    log.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(ApplicationConfiguration.class);
    rootContext.refresh();

    servletContext.setAttribute(
        WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);

    log.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfig =
        new AnnotationConfigWebApplicationContext();
    dispatcherServletConfig.setParent(rootContext);
    dispatcherServletConfig.register(DispatcherServletConfig.class);

    log.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet =
        servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfig));
    dispatcherServlet.addMapping("/tatami/*");
    dispatcherServlet.setLoadOnStartup(2);

    log.debug("Registering Meteor Servlet for online users");

    ServletRegistration.Dynamic meteorServlet =
        servletContext.addServlet("atmosphereServlet", new MeteorServlet());

    meteorServlet.setAsyncSupported(true);
    meteorServlet.addMapping("/realtime/*");
    meteorServlet.setLoadOnStartup(3);

    meteorServlet.setInitParameter(
        "org.atmosphere.servlet", "fr.ippon.tatami.web.atmosphere.users.OnlineUsersServlet");

    meteorServlet.setInitParameter(
        "org.atmosphere.cpr.broadcasterCacheClass", "org.atmosphere.cache.HeaderBroadcasterCache");

    meteorServlet.setInitParameter(
        "org.atmosphere.cpr.broadcastFilterClasses",
        "org.atmosphere.client.TrackMessageSizeFilter");

    meteorServlet.setInitParameter("org.atmosphere.useNative", "true");

    log.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter =
        servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
    EnumSet<DispatcherType> disps =
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
    springSecurityFilter.addMappingForServletNames(disps, true, "dispatcher", "atmosphereServlet");

    log.debug("Web application fully configured");
  }
Пример #2
0
  /**
   * 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, "/*");
  }
Пример #3
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("/");
  }
Пример #4
0
  @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, "/*");
  }
  @Override
  protected void registerDispatcherServlet(ServletContext servletContext) {
    String servletName = getServletName();

    WebApplicationContext servletAppContext = createServletApplicationContext();

    DispatcherServlet dispatcherServlet = new DispatcherServlet(servletAppContext);

    // throw NoHandlerFoundException to Controller when a User requests a non-existent page
    //
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

    ServletRegistration.Dynamic registration =
        servletContext.addServlet(servletName, dispatcherServlet);

    registration.setLoadOnStartup(1);
    registration.addMapping(getServletMappings());
    registration.setAsyncSupported(isAsyncSupported());

    Filter[] filters = getServletFilters();
    if (!ObjectUtils.isEmpty(filters)) {
      for (Filter filter : filters) {
        registerServletFilter(servletContext, filter);
      }
    }

    customizeRegistration(registration);
  }
  /**
   * 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());
  }
 /** Initializes H2 console. */
 private void initH2Console(ServletContext servletContext) {
   log.debug("Initialize H2 console");
   ServletRegistration.Dynamic h2ConsoleServlet =
       servletContext.addServlet("H2Console", new org.h2.server.web.WebServlet());
   h2ConsoleServlet.addMapping("/h2-console/*");
   h2ConsoleServlet.setInitParameter("-properties", "src/main/resources/");
   h2ConsoleServlet.setLoadOnStartup(1);
 }
 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("/");
 }
  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);
  }
Пример #10
0
 @Override
 public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
   // Register and map servlet
   s = new Bug51376Servlet();
   ServletRegistration.Dynamic sr = ctx.addServlet("bug51376", s);
   sr.addMapping("/bug51376");
   if (loadOnStartUp) {
     sr.setLoadOnStartup(1);
   }
 }
Пример #11
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.register(AppConfig.class);

    ServletRegistration.Dynamic dispatcher =
        servletContext.addServlet("SpringDispatcher", new DispatcherServlet(appContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }
Пример #12
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);
 }
  @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));
  }
Пример #14
0
 @Override
 public void onStartup(ServletContext servletContext) throws ServletException {
   WebApplicationContext context = getContext();
   ServletRegistration.Dynamic dispatcher =
       servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
   dispatcher.setAsyncSupported(true);
   dispatcher.setLoadOnStartup(1);
   dispatcher.addMapping("/secure/*");
   servletContext.addListener(new ContextLoaderListener(context));
   servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
 }
Пример #15
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.setServletContext(servletContext);

    ServletRegistration.Dynamic servlet =
        servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
  }
Пример #16
0
  public void onStartup(ServletContext container) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ToyboxConfiguration.class);
    ctx.setServletContext(container);

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

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
  }
 private void registerDispatcherServlet(ServletContext servletContext) {
   logger.debug(
       "Registering Dispatcher Servlet {} [name:{}]",
       WebMvcContextConfig.class.getName(),
       DISPATCHER_SERVLET);
   WebApplicationContext dispatcherContext = createContext(WebMvcContextConfig.class);
   DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext);
   ServletRegistration.Dynamic dispatcher =
       servletContext.addServlet(DISPATCHER_SERVLET, dispatcherServlet);
   dispatcher.addMapping("/");
   dispatcher.setLoadOnStartup(1);
 }
  @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");
  }
Пример #19
0
  @Override
  public void onStartup(ServletContext container) {
    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherContext =
        new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(AppConfig.class);

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher =
        container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }
  @Override
  public void onStartup(ServletContext container) throws ServletException {
    XmlWebApplicationContext appContext = new XmlWebApplicationContext();

    appContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml");

    ServletRegistration.Dynamic dispatcher =
        container.addServlet("appServlet", new DispatcherServlet(appContext));

    MultipartConfigElement multipartConfigElement =
        new MultipartConfigElement(null, 5000000, 5000000, 0);
    dispatcher.setMultipartConfig(multipartConfigElement);

    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }
Пример #21
0
  @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("/");
  }
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.register(SpringWebAppConfig.class);

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

    // UtF8 Character Filter.
    FilterRegistration.Dynamic fr =
        servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class);

    fr.setInitParameter("encoding", "UTF-8");
    fr.setInitParameter("forceEncoding", "true");
    fr.addMappingForUrlPatterns(null, true, "/*");
  }
Пример #23
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 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("/");
  }
Пример #25
0
  /** Initializes Metrics. */
  private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Initializing Metrics registries");
    servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE, metricRegistry);
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);

    log.debug("Registering Metrics Filter");
    FilterRegistration.Dynamic metricsFilter =
        servletContext.addFilter("webappMetricsFilter", new InstrumentedFilter());

    metricsFilter.addMappingForUrlPatterns(disps, true, "/*");
    metricsFilter.setAsyncSupported(true);

    log.debug("Registering Metrics Servlet");
    ServletRegistration.Dynamic metricsAdminServlet =
        servletContext.addServlet("metricsServlet", new MetricsServlet());

    metricsAdminServlet.addMapping("/metrics/metrics/*");
    metricsAdminServlet.setAsyncSupported(true);
    metricsAdminServlet.setLoadOnStartup(2);
  }
Пример #26
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);
  }
  @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, "/*");
  }
Пример #28
0
  @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("/");
  }
Пример #29
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, "/");
  }
Пример #30
0
  @Override
  public void onStartup(ServletContext container) {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebConfig.class);
    ctx.scan("com.taskstrategy.data", "com.taskstrategy.business");
    ctx.setServletContext(container);
    ctx.refresh();

    container.addListener(new ContextLoaderListener(ctx));
    container.setInitParameter("defaultHtmlEscape", "true");

    FilterRegistration.Dynamic securityFilter =
        container.addFilter(
            "securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"));
    securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    ServletRegistration.Dynamic registration =
        container.addServlet("dispatcher", new DispatcherServlet(ctx));
    registration.setLoadOnStartup(1);
    registration.setAsyncSupported(true);
    registration.addMapping("/");
  }