use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method rootServletContextResource.
@Test
public void rootServletContextResource() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
final AtomicReference<URL> rootResource = new AtomicReference<>();
this.webServer = factory.getWebServer(new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
try {
rootResource.set(servletContext.getResource("/"));
} catch (MalformedURLException ex) {
throw new ServletException(ex);
}
}
});
this.webServer.start();
assertThat(rootResource.get()).isNotNull();
}
use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class TomcatServletWebServerFactory method prepareContext.
protected void prepareContext(Host host, ServletContextInitializer[] initializers) {
File docBase = getValidDocumentRoot();
docBase = (docBase != null ? docBase : createTempDir("tomcat-docbase"));
final TomcatEmbeddedContext context = new TomcatEmbeddedContext();
context.setName(getContextPath());
context.setDisplayName(getDisplayName());
context.setPath(getContextPath());
context.setDocBase(docBase.getAbsolutePath());
context.addLifecycleListener(new FixContextListener());
context.setParentClassLoader(this.resourceLoader != null ? this.resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader());
resetDefaultLocaleMapping(context);
addLocaleMappings(context);
try {
context.setUseRelativeRedirects(false);
} catch (NoSuchMethodError ex) {
// Tomcat is < 8.0.30. Continue
}
SkipPatternJarScanner.apply(context, this.tldSkipPatterns);
WebappLoader loader = new WebappLoader(context.getParentClassLoader());
loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
loader.setDelegate(true);
context.setLoader(loader);
if (isRegisterDefaultServlet()) {
addDefaultServlet(context);
}
if (shouldRegisterJspServlet()) {
addJspServlet(context);
addJasperInitializer(context);
}
context.addLifecycleListener(new StaticResourceConfigurer(context));
ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
configureContext(context, initializersToUse);
host.addChild(context);
postProcessContext(context);
}
use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method unorderedServletContextInitializerBeans.
@Test
public void unorderedServletContextInitializerBeans() throws Exception {
addWebServerFactoryBean();
ServletContextInitializer initializer1 = mock(ServletContextInitializer.class);
ServletContextInitializer initializer2 = mock(ServletContextInitializer.class);
this.context.registerBeanDefinition("initializerBean2", beanDefinition(initializer2));
this.context.registerBeanDefinition("initializerBean1", beanDefinition(initializer1));
this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext();
verify(initializer1).onStartup(servletContext);
verify(initializer2).onStartup(servletContext);
}
use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class UndertowServletWebServerFactory method registerServletContainerInitializerToDriveServletContextInitializers.
private void registerServletContainerInitializerToDriveServletContextInitializers(DeploymentInfo deployment, ServletContextInitializer... initializers) {
ServletContextInitializer[] mergedInitializers = mergeInitializers(initializers);
Initializer initializer = new Initializer(mergedInitializers);
deployment.addServletContainerInitalizer(new ServletContainerInitializerInfo(Initializer.class, new ImmediateInstanceFactory<ServletContainerInitializer>(initializer), NO_CLASSES));
}
use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class ServletWebServerApplicationContext method selfInitialize.
private void selfInitialize(ServletContext servletContext) throws ServletException {
prepareWebApplicationContext(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);
}
}
Aggregations