Class SpringBootServletInitializer
- java.lang.Object
- org.springframework.boot.web.servlet.support.SpringBootServletInitializer
- All Implemented Interfaces:
org.springframework.web.WebApplicationInitializer
public abstract class SpringBootServletInitializer extends Object implements org.springframework.web.WebApplicationInitializer
An opinionatedWebApplicationInitializer
to run aSpringApplication
from a traditional WAR deployment. BindsServlet
,Filter
andServletContextInitializer
beans from the application context to the server.To configure the application either override the
configure(SpringApplicationBuilder)
method (callingSpringApplicationBuilder.sources(Class...)
) or make the initializer itself a@Configuration
. If you are usingSpringBootServletInitializer
in combination with otherWebApplicationInitializers
you might also want to add an@Ordered
annotation to configure a specific startup order.Note that a WebApplicationInitializer is only needed if you are building a war file and deploying it. If you prefer to run an embedded web server then you won't need this at all.
- Since:
- 2.0.0
- See Also:
configure(SpringApplicationBuilder)
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Log
logger
Constructor Summary
Constructors Constructor Description SpringBootServletInitializer()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SpringApplicationBuilder
configure(SpringApplicationBuilder builder)
Configure the application.protected org.springframework.web.context.WebApplicationContext
createRootApplicationContext(javax.servlet.ServletContext servletContext)
protected SpringApplicationBuilder
createSpringApplicationBuilder()
Returns theSpringApplicationBuilder
that is used to configure and create theSpringApplication
.void
onStartup(javax.servlet.ServletContext servletContext)
protected org.springframework.web.context.WebApplicationContext
run(SpringApplication application)
Called to run a fully configuredSpringApplication
.protected void
setRegisterErrorPageFilter(boolean registerErrorPageFilter)
Set if theErrorPageFilter
should be registered.
Field Detail
logger
protected org.apache.commons.logging.Log logger
Constructor Detail
SpringBootServletInitializer
public SpringBootServletInitializer()
Method Detail
setRegisterErrorPageFilter
protected final void setRegisterErrorPageFilter(boolean registerErrorPageFilter)
Set if theErrorPageFilter
should be registered. Set tofalse
if error page mappings should be handled via the server and not Spring Boot.- Parameters:
registerErrorPageFilter
- if theErrorPageFilter
should be registered.
onStartup
public void onStartup(javax.servlet.ServletContext servletContext) throws javax.servlet.ServletException
- Specified by:
onStartup
in interfaceorg.springframework.web.WebApplicationInitializer
- Throws:
javax.servlet.ServletException
createRootApplicationContext
protected org.springframework.web.context.WebApplicationContext createRootApplicationContext(javax.servlet.ServletContext servletContext)
createSpringApplicationBuilder
protected SpringApplicationBuilder createSpringApplicationBuilder()
Returns theSpringApplicationBuilder
that is used to configure and create theSpringApplication
. The default implementation returns a newSpringApplicationBuilder
in its default state.- Returns:
- the
SpringApplicationBuilder
. - Since:
- 1.3.0
run
protected org.springframework.web.context.WebApplicationContext run(SpringApplication application)
Called to run a fully configuredSpringApplication
.- Parameters:
application
- the application to run- Returns:
- the
WebApplicationContext
configure
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
Configure the application. Normally all you would need to do is to add sources (e.g. config classes) because other settings have sensible defaults. You might choose (for instance) to add default command line arguments, or set an active Spring profile.- Parameters:
builder
- a builder for the application context- Returns:
- the application builder
- See Also:
SpringApplicationBuilder