@Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { for (ServletContextInitializer initializer : this.initializers) { initializer.onStartup(servletContext); } }
@Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { try { for (ServletContextInitializer initializer : this.initializers) { initializer.onStartup(servletContext); } } catch (Exception ex) { this.startUpException = ex; // Prevent Tomcat from logging and re-throwing when we know we can // deal with it in the main thread, but log for information here. if (logger.isErrorEnabled()) { logger.error("Error starting Tomcat context. Exception: " + ex.getClass().getName() + ". Message: " + ex.getMessage()); } } }
private void callInitializers(WebAppContext context) throws ServletException { try { setExtendedListenerTypes(context, true); for (ServletContextInitializer initializer : this.initializers) { initializer.onStartup(context.getServletContext()); } } finally { setExtendedListenerTypes(context, false); } }
private void selfInitialize(ServletContext servletContext) throws ServletException { prepareWebApplicationContext(servletContext); registerApplicationScope(servletContext); WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(), servletContext); for (ServletContextInitializer beans : getServletContextInitializerBeans()) { beans.onStartup(servletContext); } }
private void createWebServer() { WebServer webServer = this.webServer; ServletContext servletContext = getServletContext(); if (webServer == null && servletContext == null) { ServletWebServerFactory factory = getWebServerFactory(); this.webServer = factory.getWebServer(getSelfInitializer()); } else if (servletContext != null) { try { getSelfInitializer().onStartup(servletContext); } catch (ServletException ex) { throw new ApplicationContextException("Cannot initialize servlet context", ex); } } initPropertySources(); }
@Override public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) { ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader(); Package nettyPackage = Bootstrap.class.getPackage(); String title = nettyPackage.getImplementationTitle(); String version = nettyPackage.getImplementationVersion(); logger.info("Running with " + title + " " + version); NettyEmbeddedContext context = new NettyEmbeddedContext(nettyContainerConfig,getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO); if (isRegisterDefaultServlet()) { logger.warn("This container does not support a default servlet"); } for (ServletContextInitializer initializer : initializers) { try { initializer.onStartup(context); } catch (ServletException e) { throw new RuntimeException(e); } } logger.info("nettyContainerConfig :"+nettyContainerConfig.toString()); return new NettyEmbeddedServletContainer(nettyContainerConfig, context); }
@Override public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) { ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader(); //Netty启动环境相关信息 Package nettyPackage = Bootstrap.class.getPackage(); String title = nettyPackage.getImplementationTitle(); String version = nettyPackage.getImplementationVersion(); log.info("Running with " + title + " " + version); //是否支持默认Servlet if (isRegisterDefaultServlet()) { log.warn("This container does not support a default servlet"); } //上下文 NettyContext context = new NettyContext(getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO); for (ServletContextInitializer initializer : initializers) { try { initializer.onStartup(context); } catch (ServletException e) { throw new RuntimeException(e); } } //从SpringBoot配置中获取端口,如果没有则随机生成 int port = getPort() > 0 ? getPort() : new Random().nextInt(65535 - 1024) + 1024; InetSocketAddress address = new InetSocketAddress(port); log.info("Server initialized with port: " + port); return new NettyContainer(address, context); //初始化容器并返回 }
public void init() { ServletContext servletContext = getServletContext(); if (servletContext != null) { try { getSelfInitializer().onStartup(servletContext); } catch (ServletException ex) { throw new ApplicationContextException("Cannot initialize servlet context", ex); } } initPropertySources(); }
public void init() { ServletContext servletContext = getServletContext(); if (servletContext != null) { try { getSelfInitializer().onStartup(servletContext); } catch (ServletException ex) { throw new ApplicationContextException("Cannot initialize servlet context", ex); } } initPropertySources(); }
@Test public void testOnStartup() throws ServletException { MockServletRegistrationDynamic servletRegistration = new MockServletRegistrationDynamic(); ServletContext servletContext = Mockito.mock(ServletContext.class); Mockito.when(servletContext.getServletRegistration("FacesServlet")).thenReturn(servletRegistration); this.servletContextInitializer.onStartup(servletContext); assertThat(servletRegistration.getMultipartConfig()) .isEqualTo(this.multipartConfigElement); }
@Test public void testOnStartup2() throws ServletException { MockServletRegistration servletRegistration = new MockServletRegistration(); ServletContext servletContext = Mockito.mock(ServletContext.class); Mockito.when(servletContext.getServletRegistration("FacesServlet")).thenReturn(servletRegistration); this.servletContextInitializer.onStartup(servletContext); assertThat(servletRegistration.getMultipartConfig()) .isNotEqualTo(this.multipartConfigElement); } }
private void createEmbeddedServletContainer() { EmbeddedServletContainer localContainer = this.embeddedServletContainer; ServletContext localServletContext = getServletContext(); if (localContainer == null && localServletContext == null) { EmbeddedServletContainerFactory containerFactory = getEmbeddedServletContainerFactory(); this.embeddedServletContainer = containerFactory.getEmbeddedServletContainer(getSelfInitializer()); } else if (localServletContext != null) { try { getSelfInitializer().onStartup(localServletContext); } catch (ServletException ex) { throw new ApplicationContextException("Cannot initialize servlet context", ex); } } initPropertySources(); }
private void selfInitialize(ServletContext servletContext) throws ServletException { prepareEmbeddedWebApplicationContext(servletContext); ConfigurableListableBeanFactory beanFactory = getBeanFactory(); ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes(beanFactory); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, getServletContext()); existingScopes.restore(); WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, getServletContext()); for (ServletContextInitializer beans : getServletContextInitializerBeans()) { beans.onStartup(servletContext); } }
private void selfInitialize(ServletContext servletContext) throws ServletException { prepareWebApplicationContext(servletContext); ConfigurableListableBeanFactory beanFactory = getBeanFactory(); ServletWebServerApplicationContext.ExistingWebApplicationScopes existingScopes = new ServletWebServerApplicationContext.ExistingWebApplicationScopes(beanFactory); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, getServletContext()); existingScopes.restore(); WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, getServletContext()); Collection<ServletContextInitializer> servletContextInitializerBeans; if (servletContext.getMajorVersion() >= 3) { servletContextInitializerBeans = getServletContextInitializerBeans(); } else { servletContextInitializerBeans = getLegacyServletContextInitializerBeans(); } for (ServletContextInitializer beans : servletContextInitializerBeans) { beans.onStartup(servletContext); } }
private void selfInitialize(ServletContext servletContext) throws ServletException { prepareWebApplicationContext(servletContext); ConfigurableListableBeanFactory beanFactory = getBeanFactory(); ServletWebServerApplicationContext.ExistingWebApplicationScopes existingScopes = new ServletWebServerApplicationContext.ExistingWebApplicationScopes(beanFactory); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, getServletContext()); existingScopes.restore(); WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, getServletContext()); Collection<ServletContextInitializer> servletContextInitializerBeans; if(servletContext.getMajorVersion() >= 3) { servletContextInitializerBeans = getServletContextInitializerBeans(); } else { servletContextInitializerBeans = getLegacyServletContextInitializerBeans(); } for (ServletContextInitializer beans : servletContextInitializerBeans) { beans.onStartup(servletContext); } }