Class AbstractDispatcherServletInitializer
- All Implemented Interfaces:
- WebApplicationInitializer
- Direct Known Subclasses:
- AbstractAnnotationConfigDispatcherServletInitializer
WebApplicationInitializer
 implementations that register a DispatcherServlet in the servlet context.
 Most applications should consider extending the Spring Java config subclass
 AbstractAnnotationConfigDispatcherServletInitializer.
- Since:
- 3.2
- Author:
- Arjen Poutsma, Chris Beams, Rossen Stoyanchev, Juergen Hoeller, Stephane Nicoll
- 
Field SummaryFieldsFields inherited from class org.springframework.web.context.AbstractContextLoaderInitializerlogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected FrameworkServletcreateDispatcherServlet(WebApplicationContext servletAppContext) Create aDispatcherServlet(or other kind ofFrameworkServlet-derived dispatcher) with the specifiedWebApplicationContext.protected abstract WebApplicationContextCreate a servlet application context to be provided to theDispatcherServlet.protected voidcustomizeRegistration(ServletRegistration.Dynamic registration) Optionally perform further registration customization onceregisterDispatcherServlet(ServletContext)has completed.protected ApplicationContextInitializer<?> @Nullable []Specify application context initializers to be applied to the servlet-specific application context that theDispatcherServletis being created with.Specify filters to add and map to theDispatcherServlet.protected abstract String[]Specify the servlet mapping(s) for theDispatcherServlet— for example"/","/app", etc.protected StringReturn the name under which theDispatcherServletwill be registered.protected booleanA single place to control theasyncSupportedflag for theDispatcherServletand all filters added viagetServletFilters().voidonStartup(ServletContext servletContext) Configure the givenServletContextwith any servlets, filters, listeners context-params and attributes necessary for initializing this web application.protected voidregisterDispatcherServlet(ServletContext servletContext) Register aDispatcherServletagainst the given servlet context.protected FilterRegistration.DynamicregisterServletFilter(ServletContext servletContext, Filter filter) Add the given filter to the ServletContext and map it to theDispatcherServletas follows: a default filter name is chosen based on its concrete type theasyncSupportedflag is set depending on the return value ofasyncSupporteda filter mapping is created with dispatcher typesREQUEST,FORWARD,INCLUDE, and conditionallyASYNCdepending on the return value ofasyncSupportedMethods inherited from class org.springframework.web.context.AbstractContextLoaderInitializercreateRootApplicationContext, getRootApplicationContextInitializers, registerContextLoaderListener
- 
Field Details- 
DEFAULT_SERVLET_NAMEThe default servlet name. Can be customized by overridinggetServletName().- See Also:
 
 
- 
- 
Constructor Details- 
AbstractDispatcherServletInitializerpublic AbstractDispatcherServletInitializer()
 
- 
- 
Method Details- 
onStartupDescription copied from interface:WebApplicationInitializerConfigure the givenServletContextwith any servlets, filters, listeners context-params and attributes necessary for initializing this web application. See examples above.- Specified by:
- onStartupin interface- WebApplicationInitializer
- Overrides:
- onStartupin class- AbstractContextLoaderInitializer
- Parameters:
- servletContext- the- ServletContextto initialize
- Throws:
- ServletException- if any call against the given- ServletContextthrows a- ServletException
 
- 
registerDispatcherServletRegister aDispatcherServletagainst the given servlet context.This method will create a DispatcherServletwith the name returned bygetServletName(), initializing it with the application context returned fromcreateServletApplicationContext(), and mapping it to the patterns returned fromgetServletMappings().Further customization can be achieved by overriding customizeRegistration(ServletRegistration.Dynamic)orcreateDispatcherServlet(WebApplicationContext).- Parameters:
- servletContext- the context to register the servlet against
 
- 
getServletNameReturn the name under which theDispatcherServletwill be registered. Defaults toDEFAULT_SERVLET_NAME.- See Also:
 
- 
createServletApplicationContextCreate a servlet application context to be provided to theDispatcherServlet.The returned context is delegated to Spring's DispatcherServlet(WebApplicationContext). As such, it typically contains controllers, view resolvers, locale resolvers, and other web-related beans.- See Also:
 
- 
createDispatcherServletCreate aDispatcherServlet(or other kind ofFrameworkServlet-derived dispatcher) with the specifiedWebApplicationContext.Note: This allows for any FrameworkServletsubclass as of 4.2.3. Previously, it insisted on returning aDispatcherServletor subclass thereof.
- 
getServletApplicationContextInitializersSpecify application context initializers to be applied to the servlet-specific application context that theDispatcherServletis being created with.- Since:
- 4.2
- See Also:
 
- 
getServletMappingsSpecify the servlet mapping(s) for theDispatcherServlet— for example"/","/app", etc.- See Also:
 
- 
getServletFilters
- 
registerServletFilterprotected FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) Add the given filter to the ServletContext and map it to theDispatcherServletas follows:- a default filter name is chosen based on its concrete type
- the asyncSupportedflag is set depending on the return value ofasyncSupported
- a filter mapping is created with dispatcher types REQUEST,FORWARD,INCLUDE, and conditionallyASYNCdepending on the return value ofasyncSupported
 If the above defaults are not suitable or insufficient, override this method and register filters directly with the ServletContext.- Parameters:
- servletContext- the servlet context to register filters with
- filter- the filter to be registered
- Returns:
- the filter registration
 
- 
isAsyncSupportedprotected boolean isAsyncSupported()A single place to control theasyncSupportedflag for theDispatcherServletand all filters added viagetServletFilters().The default value is "true". 
- 
customizeRegistrationOptionally perform further registration customization onceregisterDispatcherServlet(ServletContext)has completed.- Parameters:
- registration- the- DispatcherServletregistration to be customized
- See Also:
 
 
-