类 AbstractDispatcherServletInitializer
- java.lang.Object
- org.springframework.web.context.AbstractContextLoaderInitializer
- org.springframework.web.servlet.support.AbstractDispatcherServletInitializer
- 所有已实现的接口:
WebApplicationInitializer
public abstract class AbstractDispatcherServletInitializer extends AbstractContextLoaderInitializer
Base class forWebApplicationInitializerimplementations that register aDispatcherServletin the servlet context.Concrete implementations are required to implement
createServletApplicationContext(), as well asgetServletMappings(), both of which get invoked fromregisterDispatcherServlet(ServletContext). Further customization can be achieved by overridingcustomizeRegistration(ServletRegistration.Dynamic).Because this class extends from
AbstractContextLoaderInitializer, concrete implementations are also required to implementAbstractContextLoaderInitializer.createRootApplicationContext()to set up a parent "root" application context. If a root context is not desired, implementations can simply returnnullin thecreateRootApplicationContext()implementation.- 从以下版本开始:
- 3.2
- 作者:
- Arjen Poutsma, Chris Beams, Rossen Stoyanchev, Juergen Hoeller, Stephane Nicoll
字段概要
字段 修饰符和类型 字段 说明 static StringDEFAULT_SERVLET_NAMEThe default servlet name.从类继承的字段 org.springframework.web.context.AbstractContextLoaderInitializer
logger
构造器概要
构造器 构造器 说明 AbstractDispatcherServletInitializer()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected FrameworkServletcreateDispatcherServlet(WebApplicationContext servletAppContext)Create aDispatcherServlet(or other kind ofFrameworkServlet-derived dispatcher) with the specifiedWebApplicationContext.protected abstract WebApplicationContextcreateServletApplicationContext()Create 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<?>[]getServletApplicationContextInitializers()Specify application context initializers to be applied to the servlet-specific application context that theDispatcherServletis being created with.protected Filter[]getServletFilters()Specify filters to add and map to theDispatcherServlet.protected abstract String[]getServletMappings()Specify the servlet mapping(s) for theDispatcherServlet— for example"/","/app", etc.protected StringgetServletName()Return the name under which theDispatcherServletwill be registered.protected booleanisAsyncSupported()A 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 ofasyncSupported从类继承的方法 org.springframework.web.context.AbstractContextLoaderInitializer
createRootApplicationContext, getRootApplicationContextInitializers, registerContextLoaderListener
字段详细资料
DEFAULT_SERVLET_NAME
public static final String DEFAULT_SERVLET_NAME
The default servlet name. Can be customized by overridinggetServletName().- 另请参阅:
- 常量字段值
构造器详细资料
AbstractDispatcherServletInitializer
public AbstractDispatcherServletInitializer()
方法详细资料
onStartup
public void onStartup(ServletContext servletContext) throws ServletException
从接口复制的说明:WebApplicationInitializerConfigure the givenServletContextwith any servlets, filters, listeners context-params and attributes necessary for initializing this web application. See examples above.- 指定者:
onStartup在接口中WebApplicationInitializer- 覆盖:
onStartup在类中AbstractContextLoaderInitializer- 参数:
servletContext- theServletContextto initialize- 抛出:
ServletException- if any call against the givenServletContextthrows aServletException
registerDispatcherServlet
protected void registerDispatcherServlet(ServletContext servletContext)
Register 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).- 参数:
servletContext- the context to register the servlet against
getServletName
protected String getServletName()
Return the name under which theDispatcherServletwill be registered. Defaults toDEFAULT_SERVLET_NAME.
createServletApplicationContext
protected abstract WebApplicationContext createServletApplicationContext()
Create 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.
createDispatcherServlet
protected FrameworkServlet createDispatcherServlet(WebApplicationContext servletAppContext)
Create 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.
getServletApplicationContextInitializers
protected ApplicationContextInitializer<?>[] getServletApplicationContextInitializers()
Specify application context initializers to be applied to the servlet-specific application context that theDispatcherServletis being created with.
getServletMappings
protected abstract String[] getServletMappings()
Specify the servlet mapping(s) for theDispatcherServlet— for example"/","/app", etc.
getServletFilters
protected Filter[] getServletFilters()
Specify filters to add and map to theDispatcherServlet.- 返回:
- an array of filters or
null - 另请参阅:
registerServletFilter(ServletContext, Filter)
registerServletFilter
protected 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.- 参数:
servletContext- the servlet context to register filters withfilter- the filter to be registered- 返回:
- the filter registration
isAsyncSupported
protected boolean isAsyncSupported()
A single place to control theasyncSupportedflag for theDispatcherServletand all filters added viagetServletFilters().The default value is "true".
customizeRegistration
protected void customizeRegistration(ServletRegistration.Dynamic registration)
Optionally perform further registration customization onceregisterDispatcherServlet(ServletContext)has completed.- 参数:
registration- theDispatcherServletregistration to be customized- 另请参阅:
registerDispatcherServlet(ServletContext)