public abstract class AbstractDispatcherHandlerInitializer extends java.lang.Object implements WebApplicationInitializer
WebApplicationInitializer
implementations that register a DispatcherHandler
in the servlet
context, wrapping it in a ServletHttpHandlerAdapter
.
Most applications should consider extending the Spring Java config, sub-class
AbstractAnnotationConfigDispatcherHandlerInitializer
.
AbstractServletHttpHandlerAdapterInitializer
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_SERVLET_MAPPING
The default servlet mapping.
|
static java.lang.String |
DEFAULT_SERVLET_NAME
The default servlet name.
|
Constructor and Description |
---|
AbstractDispatcherHandlerInitializer() |
Modifier and Type | Method and Description |
---|---|
protected abstract ApplicationContext |
createApplicationContext()
Create an application context to be provided to the
DispatcherHandler . |
protected WebHandler |
createDispatcherHandler(ApplicationContext applicationContext)
Create a
DispatcherHandler (or other kind of WebHandler -derived
dispatcher) with the specified ApplicationContext . |
protected ServletHttpHandlerAdapter |
createHandlerAdapter(WebHandler webHandler)
Create a
ServletHttpHandlerAdapter . |
protected void |
customizeRegistration(ServletRegistration.Dynamic registration)
Optionally perform further registration customization once
registerDispatcherHandler(ServletContext) has completed. |
protected java.lang.String |
getServletMapping()
Specify the servlet mapping for the
ServletHttpHandlerAdapter . |
protected java.lang.String |
getServletName()
Return the name under which the
ServletHttpHandlerAdapter will be registered. |
void |
onStartup(ServletContext servletContext)
Configure the given
ServletContext with any servlets, filters, listeners
context-params and attributes necessary for initializing this web application. |
protected void |
refreshApplicationContext(ApplicationContext context)
Refresh the given application context, if necessary.
|
protected void |
registerCloseListener(ServletContext servletContext,
ApplicationContext applicationContext)
Register a
ServletContextListener that closes the given application context
when the servlet context is destroyed. |
protected void |
registerDispatcherHandler(ServletContext servletContext)
Register a
DispatcherHandler against the given servlet context. |
public static final java.lang.String DEFAULT_SERVLET_NAME
getServletName()
.public static final java.lang.String DEFAULT_SERVLET_MAPPING
getServletMapping()
.public AbstractDispatcherHandlerInitializer()
public void onStartup(ServletContext servletContext) throws ServletException
WebApplicationInitializer
ServletContext
with any servlets, filters, listeners
context-params and attributes necessary for initializing this web application. See
examples above.onStartup
in interface WebApplicationInitializer
servletContext
- the ServletContext
to initializeServletException
- if any call against the given ServletContext
throws a ServletException
protected void registerDispatcherHandler(ServletContext servletContext)
DispatcherHandler
against the given servlet context.
This method will create a DispatcherHandler
, initializing it with the application
context returned from createApplicationContext()
. The created handler will be
wrapped in a ServletHttpHandlerAdapter
servlet with the name
returned by getServletName()
, mapping it to the pattern
returned from getServletMapping()
.
Further customization can be achieved by overriding customizeRegistration(ServletRegistration.Dynamic)
or
createDispatcherHandler(ApplicationContext)
.
servletContext
- the context to register the servlet againstprotected java.lang.String getServletName()
ServletHttpHandlerAdapter
will be registered.
Defaults to DEFAULT_SERVLET_NAME
.protected abstract ApplicationContext createApplicationContext()
DispatcherHandler
.
The returned context is delegated to Spring's
DispatcherHandler.DispatcherHandler(ApplicationContext)
. As such,
it typically contains controllers, view resolvers, and other web-related beans.
protected void refreshApplicationContext(ApplicationContext context)
protected WebHandler createDispatcherHandler(ApplicationContext applicationContext)
DispatcherHandler
(or other kind of WebHandler
-derived
dispatcher) with the specified ApplicationContext
.protected ServletHttpHandlerAdapter createHandlerAdapter(WebHandler webHandler)
ServletHttpHandlerAdapter
.
Default implementation returns a ServletHttpHandlerAdapter
with the provided
webHandler
.
protected java.lang.String getServletMapping()
ServletHttpHandlerAdapter
.
Default implementation returns /
.
protected void customizeRegistration(ServletRegistration.Dynamic registration)
registerDispatcherHandler(ServletContext)
has completed.registration
- the ServletHttpHandlerAdapter
registration to be customizedregisterDispatcherHandler(ServletContext)
protected void registerCloseListener(ServletContext servletContext, ApplicationContext applicationContext)
ServletContextListener
that closes the given application context
when the servlet context is destroyed.servletContext
- the servlet context to listen toapplicationContext
- the application context that is to be closed when
servletContext
is destroyed