Java 类javax.servlet.ServletRegistration.Dynamic 实例源码

项目:incubator-servicecomb-java-chassis    文件:TestRestServletInitializer.java   
@Test
public void testOnStartup() throws Exception {
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  String urlPattern = "/rest/*";
  configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, urlPattern);

  ServletContext servletContext = mock(ServletContext.class);
  Dynamic dynamic = mock(Dynamic.class);
  when(servletContext.addServlet(RestServletInjector.SERVLET_NAME, RestServlet.class)).thenReturn(dynamic);

  RestServletInitializer restServletInitializer = new RestServletInitializer();
  restServletInitializer.setPort(TEST_PORT);
  restServletInitializer.onStartup(servletContext);

  verify(dynamic).setAsyncSupported(true);
  verify(dynamic).addMapping(urlPattern);
  verify(dynamic).setLoadOnStartup(0);
}
项目:incubator-servicecomb-java-chassis    文件:RestServletInjector.java   
public Dynamic inject(ServletContext servletContext, String urlPattern) {
  String[] urlPatterns = splitUrlPattern(urlPattern);
  if (urlPatterns.length == 0) {
    LOGGER.warn("urlPattern is empty, ignore register {}.", SERVLET_NAME);
    return null;
  }

  String listenAddress = ServletConfig.getLocalServerAddress();
  if (!ServletUtils.canPublishEndpoint(listenAddress)) {
    LOGGER.warn("ignore register {}.", SERVLET_NAME);
    return null;
  }

  // dynamic deploy a servlet to handle serviceComb RESTful request
  Dynamic dynamic = servletContext.addServlet(SERVLET_NAME, RestServlet.class);
  dynamic.setAsyncSupported(true);
  dynamic.addMapping(urlPatterns);
  dynamic.setLoadOnStartup(0);
  LOGGER.info("RESTful servlet url pattern: {}.", Arrays.toString(urlPatterns));

  return dynamic;
}
项目:incubator-servicecomb-java-chassis    文件:TestRestServletInjector.java   
@Test
public void testDefaultInjectNotListen(@Mocked ServletContext servletContext,
    @Mocked Dynamic dynamic) throws UnknownHostException, IOException {
  try (ServerSocket ss = new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1"))) {
    int port = ss.getLocalPort();

    new Expectations(ServletConfig.class) {
      {
        ServletConfig.getServletUrlPattern();
        result = "/*";
        ServletConfig.getLocalServerAddress();
        result = "127.0.0.1:" + port;
      }
    };
  }

  Assert.assertEquals(null, RestServletInjector.defaultInject(servletContext));
}
项目:incubator-servicecomb-java-chassis    文件:TestRestServletInjector.java   
@Test
public void testDefaultInjectListen(@Mocked ServletContext servletContext,
    @Mocked Dynamic dynamic) throws UnknownHostException, IOException {
  try (ServerSocket ss = new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1"))) {
    int port = ss.getLocalPort();

    new Expectations(ServletConfig.class) {
      {
        ServletConfig.getServletUrlPattern();
        result = "/rest/*";
        ServletConfig.getLocalServerAddress();
        result = "127.0.0.1:" + port;
      }
    };

    Assert.assertEquals(dynamic, RestServletInjector.defaultInject(servletContext));
  }
}
项目:autopivot    文件:AutoPivotWebAppInitializer.java   
/**
 * Configure the given {@link ServletContext} with any servlets, filters, listeners
 * context-params and attributes necessary for initializing this web application. See examples
 * {@linkplain WebApplicationInitializer above}.
 *
 * @param servletContext the {@code ServletContext} to initialize
 * @throws ServletException if any call against the given {@code ServletContext} throws a {@code ServletException}
 */
public void onStartup(ServletContext servletContext) throws ServletException {
    // Spring Context Bootstrapping
    AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
    rootAppContext.register(AutoPivotConfig.class);
    servletContext.addListener(new ContextLoaderListener(rootAppContext));

    // Set the session cookie name. Must be done when there are several servers (AP,
    // Content server, ActiveMonitor) with the same URL but running on different ports.
    // Cookies ignore the port (See RFC 6265).
    CookieUtil.configure(servletContext.getSessionCookieConfig(), CookieUtil.COOKIE_NAME);

    // The main servlet/the central dispatcher
    final DispatcherServlet servlet = new DispatcherServlet(rootAppContext);
    servlet.setDispatchOptionsRequest(true);
    Dynamic dispatcher = servletContext.addServlet("springDispatcherServlet", servlet);
    dispatcher.addMapping("/*");
    dispatcher.setLoadOnStartup(1);

    // Spring Security Filter
    final FilterRegistration.Dynamic springSecurity = servletContext.addFilter(SPRING_SECURITY_FILTER_CHAIN, new DelegatingFilterProxy());
    springSecurity.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:nymph    文件:WebXmlStarter.java   
/**
 * 动态的加载过滤器, 不需要再webxml中配置, 只需要在yml文件中配置全路径即可, 配置多个过滤器时可以形成过滤器链
 * @param context   ServletContext servlet上下文
 * @param filters   过滤器的全路径, 可以配置多个
 */
private void loadCustomFilter(ServletContext context, List<String> filters) {
    filters.forEach(filter -> {
        String urlPattern = "/*";

        if (filter.indexOf("@") > 0) {
            String[] split = filter.split("@");
            urlPattern = split[1];
            filter = split[0];
        }
        javax.servlet.FilterRegistration.Dynamic dynamic =
                context.addFilter(filter, filter);

        dynamic.setAsyncSupported(true); // 设置过滤器的异步支持
        dynamic.addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST), true, urlPattern);
    });
}
项目:flow-platform    文件:AppInit.java   
private void initGitServlet(Path gitWorkspace, ServletContext servletContext) throws IOException {
    if (!Files.exists(gitWorkspace)) {
        Files.createDirectories(gitWorkspace);
    }

    // add git servlet mapping
    Dynamic gitServlet = servletContext.addServlet("git-servlet", new GitServlet());
    gitServlet.addMapping("/git/*");
    gitServlet.setInitParameter("base-path", gitWorkspace.toString());
    gitServlet.setInitParameter("export-all", "true");
    gitServlet.setAsyncSupported(true);
    gitServlet.setLoadOnStartup(1);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServletRegistrationBean.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    Assert.notNull(this.servlet, "Servlet must not be null");
    String name = getServletName();
    if (!isEnabled()) {
        logger.info("Servlet " + name + " was not registered (disabled)");
        return;
    }
    logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings);
    Dynamic added = servletContext.addServlet(name, this.servlet);
    if (added == null) {
        logger.info("Servlet " + name + " was not registered "
                + "(possibly already registered?)");
        return;
    }
    configure(added);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ServletRegistrationBean.java   
/**
 * Configure registration settings. Subclasses can override this method to perform
 * additional configuration if required.
 * @param registration the registration
 */
protected void configure(ServletRegistration.Dynamic registration) {
    super.configure(registration);
    String[] urlMapping = this.urlMappings
            .toArray(new String[this.urlMappings.size()]);
    if (urlMapping.length == 0 && this.alwaysMapUrl) {
        urlMapping = DEFAULT_MAPPINGS;
    }
    if (!ObjectUtils.isEmpty(urlMapping)) {
        registration.addMapping(urlMapping);
    }
    registration.setLoadOnStartup(this.loadOnStartup);
    if (this.multipartConfig != null) {
        registration.setMultipartConfig(this.multipartConfig);
    }
}
项目:spring-boot-concourse    文件:ServletRegistrationBean.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    Assert.notNull(this.servlet, "Servlet must not be null");
    String name = getServletName();
    if (!isEnabled()) {
        logger.info("Servlet " + name + " was not registered (disabled)");
        return;
    }
    logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings);
    Dynamic added = servletContext.addServlet(name, this.servlet);
    if (added == null) {
        logger.info("Servlet " + name + " was not registered "
                + "(possibly already registered?)");
        return;
    }
    configure(added);
}
项目:spring-boot-concourse    文件:ServletRegistrationBean.java   
/**
 * Configure registration settings. Subclasses can override this method to perform
 * additional configuration if required.
 * @param registration the registration
 */
protected void configure(ServletRegistration.Dynamic registration) {
    super.configure(registration);
    String[] urlMapping = this.urlMappings
            .toArray(new String[this.urlMappings.size()]);
    if (urlMapping.length == 0 && this.alwaysMapUrl) {
        urlMapping = DEFAULT_MAPPINGS;
    }
    if (!ObjectUtils.isEmpty(urlMapping)) {
        registration.addMapping(urlMapping);
    }
    registration.setLoadOnStartup(this.loadOnStartup);
    if (this.multipartConfig != null) {
        registration.setMultipartConfig(this.multipartConfig);
    }
}
项目:contestparser    文件:ServletRegistrationBean.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    Assert.notNull(this.servlet, "Servlet must not be null");
    String name = getServletName();
    if (!isEnabled()) {
        logger.info("Servlet " + name + " was not registered (disabled)");
        return;
    }
    logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings);
    Dynamic added = servletContext.addServlet(name, this.servlet);
    if (added == null) {
        logger.info("Servlet " + name + " was not registered "
                + "(possibly already registered?)");
        return;
    }
    configure(added);
}
项目:contestparser    文件:ServletRegistrationBean.java   
/**
 * Configure registration settings. Subclasses can override this method to perform
 * additional configuration if required.
 * @param registration the registration
 */
protected void configure(ServletRegistration.Dynamic registration) {
    super.configure(registration);
    String[] urlMapping = this.urlMappings
            .toArray(new String[this.urlMappings.size()]);
    if (urlMapping.length == 0 && this.alwaysMapUrl) {
        urlMapping = DEFAULT_MAPPINGS;
    }
    if (!ObjectUtils.isEmpty(urlMapping)) {
        registration.addMapping(urlMapping);
    }
    registration.setLoadOnStartup(this.loadOnStartup);
    if (this.multipartConfig != null) {
        registration.setMultipartConfig(this.multipartConfig);
    }
}
项目:sitemonitoring-production    文件:WebXmlCommon.java   
public static void initialize(ServletContext servletContext, boolean dev) throws ServletException {
    FacesInitializer facesInitializer = new FacesInitializer();

    servletContext.setInitParameter("primefaces.FONT_AWESOME", "true");
    servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true");
    if (dev) {
        servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "0");
        servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
    } else {
        servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "-1");
        servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Production");
    }
    servletContext.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE));

    Set<Class<?>> clazz = new HashSet<Class<?>>();
    clazz.add(WebXmlSpringBoot.class);
    facesInitializer.onStartup(clazz, servletContext);

    Dynamic startBrowserServlet = servletContext.addServlet("StartBrowserServlet", StartBrowserServlet.class);
    startBrowserServlet.setLoadOnStartup(2);
}
项目:simplebank    文件:Application.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext applicationContext = buildApplicationContext();
    Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(applicationContext));
    appServlet.setLoadOnStartup(1);
    appServlet.addMapping("/api/*", "/app/*");

    MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet(applicationContext);
    messageDispatcherServlet.setTransformWsdlLocations(true);
    Dynamic wsServlet = servletContext.addServlet("wsServlet", messageDispatcherServlet);
    wsServlet.setLoadOnStartup(2);
    wsServlet.addMapping("/ws/*");

    FilterRegistration.Dynamic filter = servletContext.addFilter("openEntityManagerInViewFilter", buildOpenEntityManagerFilter());
    filter.addMappingForUrlPatterns(getDispatcherTypes(), false, "/api/*", "/app/*","/ws/*");

    servletContext.addListener(new ContextLoaderListener(applicationContext));
}
项目:spring-crud-programmatically    文件:Initializer.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException 
{
       AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
       ctx.register(WebAppConfig.class);
       servletContext.addListener(new ContextLoaderListener(ctx));

       // http://stackoverflow.com/questions/7903556/programming-spring-mvc-controller-and-jsp-for-httpdelete
       // https://cwiki.apache.org/confluence/display/GMOxDOC30/cviewer-javaee6+-+Programmatically+register+servlets+and+filters
       // https://gist.github.com/krams915/4238821        
       servletContext
        .addFilter("hiddenHttpMethodFilter", "org.springframework.web.filter.HiddenHttpMethodFilter")
        .addMappingForUrlPatterns(null, false, "/*");

       // This DispatcherServlet is a front controller that forwards the incoming HTTP requests to the specific controler classes
       Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
       servlet.addMapping("/");
       servlet.setLoadOnStartup(1);
}
项目:ldp4j    文件:BootstrapContextListener.java   
private static void registerCXFServlet(ServletContext servletContext) {
    LOGGER.info("Registering CXF servlet...");
    Dynamic dynamic =
        servletContext.
            addServlet(
                "LDP4jFrontendServerServlet",
                "org.apache.cxf.transport.servlet.CXFServlet");
    dynamic.addMapping("/*");
    /** See https://issues.apache.org/jira/browse/CXF-5068 */
    dynamic.setInitParameter("disable-address-updates","true");
    /** Required for testing */
    dynamic.setInitParameter("static-welcome-file","/index.html");
    dynamic.setInitParameter("static-resources-list","/index.html");
    dynamic.setLoadOnStartup(1);
    LOGGER.info("CXF servlet registered.");
}
项目:spring-crud-programmatically    文件:Initializer.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException 
{
       AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
       ctx.register(WebAppConfig.class);
       servletContext.addListener(new ContextLoaderListener(ctx));

       // http://stackoverflow.com/questions/7903556/programming-spring-mvc-controller-and-jsp-for-httpdelete
       // https://cwiki.apache.org/confluence/display/GMOxDOC30/cviewer-javaee6+-+Programmatically+register+servlets+and+filters
       // https://gist.github.com/krams915/4238821        
       servletContext
        .addFilter("hiddenHttpMethodFilter", "org.springframework.web.filter.HiddenHttpMethodFilter")
        .addMappingForUrlPatterns(null, false, "/*");

       // This DispatcherServlet is a front controller that forwards the incoming HTTP requests to the specific controler classes
       Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
       servlet.addMapping("/");
       servlet.setLoadOnStartup(1);
}
项目:incubator-servicecomb-java-chassis    文件:TestRestServletInitializer.java   
@Test
public void testOnStartupWhenUrlPatternNotSet() throws ServletException {
  ServletContext servletContext = mock(ServletContext.class);
  Dynamic dynamic = mock(Dynamic.class);
  when(servletContext.addServlet(RestServletInjector.SERVLET_NAME, RestServlet.class)).thenReturn(dynamic);

  RestServletInitializer restServletInitializer = new RestServletInitializer();
  restServletInitializer.setPort(TEST_PORT);
  restServletInitializer.onStartup(servletContext);

  verify(dynamic).setAsyncSupported(true);
  verify(dynamic).addMapping(ServletConfig.DEFAULT_URL_PATTERN);
  verify(dynamic).setLoadOnStartup(0);
}
项目:incubator-servicecomb-java-chassis    文件:TestCseXmlWebApplicationContext.java   
@Test
public void testInjectServlet(@Mocked ConfigurableListableBeanFactory beanFactory) {
  Holder<Boolean> holder = new Holder<>();
  new MockUp<RestServletInjector>() {
    @Mock
    public Dynamic defaultInject(ServletContext servletContext) {
      holder.value = true;
      return null;
    }
  };

  context.invokeBeanFactoryPostProcessors(beanFactory);

  Assert.assertTrue(holder.value);
}
项目:incubator-servicecomb-java-chassis    文件:TestRestServletInjector.java   
@Test
public void testDefaultInjectEmptyUrlPattern(@Mocked ServletContext servletContext, @Mocked Dynamic dynamic) {
  new Expectations(ServletConfig.class) {
    {
      ServletConfig.getServletUrlPattern();
      result = null;
    }
  };

  Assert.assertEquals(null, RestServletInjector.defaultInject(servletContext));
}
项目:tomcat7    文件:StandardContext.java   
/**
 * hook to register that we need to scan for security annotations.
 * @param wrapper   The wrapper for the Servlet that was added
 */
public ServletRegistration.Dynamic dynamicServletAdded(Wrapper wrapper) {
    Servlet s = wrapper.getServlet();
    if (s != null && createdServlets.contains(s)) {
        // Mark the wrapper to indicate annotations need to be scanned
        wrapper.setServletSecurityAnnotationScanRequired(true);
    }
    return new ApplicationServletRegistration(wrapper, this);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // ③
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
    servlet.setAsyncSupported(true);//①
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
项目:springMvc4.x-project    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext)
        throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MyMvcConfig.class);
    ctx.setServletContext(servletContext); // ②

    Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
    servlet.setAsyncSupported(true);//①
}
项目:hello-spring    文件:WebInitializer.java   
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(MyMvcConfig.class);
    context.setServletContext(servletContext);
    Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
    // 开启异步支持
    servlet.setAsyncSupported(true);
}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardContext.java   
/**
 * hook to register that we need to scan for security annotations.
 * @param wrapper   The wrapper for the Servlet that was added
 */
public ServletRegistration.Dynamic dynamicServletAdded(Wrapper wrapper) {
    Servlet s = wrapper.getServlet();
    if (s != null && createdServlets.contains(s)) {
        // Mark the wrapper to indicate annotations need to be scanned
        wrapper.setServletSecurityAnnotationScanRequired(true);
    }
    return new ApplicationServletRegistration(wrapper, this);
}
项目:lazycat    文件:StandardContext.java   
/**
 * hook to register that we need to scan for security annotations.
 * 
 * @param wrapper
 *            The wrapper for the Servlet that was added
 */
public ServletRegistration.Dynamic dynamicServletAdded(Wrapper wrapper) {
    Servlet s = wrapper.getServlet();
    if (s != null && createdServlets.contains(s)) {
        // Mark the wrapper to indicate annotations need to be scanned
        wrapper.setServletSecurityAnnotationScanRequired(true);
    }
    return new ApplicationServletRegistration(wrapper, this);
}
项目:mycore    文件:MCRUploadServletDeployer.java   
@Override
public void startUp(ServletContext servletContext) {
    if (servletContext != null) {
        String servletName = "MCRUploadViaFormServlet";
        MultipartConfigElement multipartConfig = getMultipartConfig();
        try {
            checkTempStoragePath(multipartConfig.getLocation());
        } catch (IOException e) {
            throw new MCRConfigurationException("Could not setup " + servletName + "!", e);
        }
        Dynamic uploadServlet = servletContext.addServlet(servletName, MCRUploadViaFormServlet.class);
        uploadServlet.addMapping("/servlets/MCRUploadViaFormServlet");
        uploadServlet.setMultipartConfig(multipartConfig);
    }
}
项目:seckill    文件:WebAppInitializer.java   
public void onStartup(ServletContext servletContext) throws ServletException {  
     AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();  
     ctx.register(AppConfig.class);  
     ctx.setServletContext(servletContext);    
     Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));  
     dynamic.addMapping("/");  
     dynamic.setLoadOnStartup(1);  
}
项目:Audit4j-Hibernate    文件:WebInitializer.java   
public void onStartup(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.setConfigLocation("org.audt4j.demo.hibernate.config");
    servletContext.addListener(new ContextLoaderListener(ctx));
    ctx.setServletContext(servletContext);
    Dynamic servlet = servletContext.addServlet("dispatcher",
            new DispatcherServlet(ctx));
    servlet.addMapping("/*");
    servlet.setLoadOnStartup(1);
    FilterRegistration.Dynamic springSecurityFilterChain = servletContext
            .addFilter("springSecurityFilterChain",
                    new DelegatingFilterProxy());
    springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");
    springSecurityFilterChain.setAsyncSupported(true);
}