WebApplicationInitializer provides a way to programmatically represent a good portion of a standard web.xml file - the servlets, filters, listeners.
However I have
Using spring-boot it's pretty easy.
I am sure it could be done without spring boot as well by extending SpringServletContainerInitializer. It seems that is what it is specifically designed for.
Servlet 3.0 ServletContainerInitializer designed to support code-based configuration of the servlet container using Spring's WebApplicationInitializer SPI as opposed to (or possibly in combination with) the traditional web.xml-based approach.
Sample code (using SpringBootServletInitializer)
public class MyServletInitializer extends SpringBootServletInitializer {
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory containerFactory = new TomcatEmbeddedServletContainerFactory(8080);
// configure error pages
containerFactory.getErrorPages().add(new ErrorPage(HttpStatus.UNAUTHORIZED, "/errors/401"));
// configure session timeout
containerFactory.setSessionTimeout(20);
return containerFactory;
}
}