|PREV CLASS NEXT CLASS||FRAMES NO FRAMES|
|SUMMARY: NESTED | FIELD | CONSTR | METHOD||DETAIL: FIELD | CONSTR | METHOD|
ServletContainerInitializerdesigned to support code-based configuration of the servlet container using Spring's
WebApplicationInitializerSPI as opposed to (or possibly in combination with) the traditional
Mechanism of OperationThis class will be loaded and instantiated and have its
onStartupmethod invoked by any Servlet 3.0-compliant container during container startup assuming that the
spring-webmodule JAR is present on the classpath. This occurs through the JAR Services API
ServiceLoader.load(Class)method detecting the
META-INF/services/javax.servlet.ServletContainerInitializerservice provider configuration file. See the JAR Services API documentation as well as section 8.2.4 of the Servlet 3.0 Final Draft specification for complete details.
when in combination with
If a web application does include a
WEB-INF/web.xmlfile, it is important to understand that neither this nor any other
ServletContextInitializerwill be processed unless the
versionattribute is >= "3.0" and the
xsi:schemaLocationfor "http://java.sun.com/xml/ns/javaee" is set to "http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd".
Relationship to Spring'sSpring's
WebApplicationInitializerSPI consists of just one method:
WebApplicationInitializer.onStartup(ServletContext). The signature is intentionally quite similar to
ServletContainerInitializer#onStartup(Set, ServletContext): simply put,
SpringServletContainerInitializeris responsible for instantiating and delegating the
ServletContextto any user-defined
WebApplicationInitializerimplementations. It is then the responsibility of each
WebApplicationInitializerto do the actual work of initializing the
ServletContext. The exact process of delegation is described in detail in the
General NotesIn general, this class should be viewed as supporting infrastructure for the more important and user-facing
WebApplicationInitializerSPI. Taking advantage of this container initializer is also completely optional: while it is true that this initializer will be loaded and invoked under all Servlet 3.0+ runtimes, it remains the user's choice whether to make any
WebApplicationInitializerimplementations available on the classpath. If no
WebApplicationInitializertypes are detected, this container initializer will have no effect.
Note that use of this container initializer and of
WebApplicationInitializeris not in any way "tied" to Spring MVC other than the fact that the types are shipped in the
spring-webmodule JAR. Rather, they can be considered general-purpose in their ability to facilitate convenient code-based configuration of the
ServletContext. Said another way, any servlet, listener, or filter may be registered within a
WebApplicationInitializer, not just Spring MVC-specific components.
This class is not designed for nor intended to be extended. It should be considered an internal type, with
WebApplicationInitializerbeing the public-facing SPI.
WebApplicationInitializerJavadoc for examples and detailed usage recommendations.