ServletContainerInitializer designed to support code-based
configuration of the servlet container using Spring's WebApplicationInitializer
SPI as opposed to (or possibly in combination with) the traditional
web.xml-based approach.
onStartup
method invoked by any Servlet-compliant container during container startup assuming
that the spring-web module JAR is present on the classpath. This occurs through
the JAR Services API ServiceLoader#load(Class) method detecting the
spring-web module's META-INF/services/jakarta.servlet.ServletContainerInitializer
service provider configuration file.
web.xmlmetadata-complete attribute in
web.xml, which controls scanning for Servlet annotations or through an
<absolute-ordering> element also in web.xml, which controls which
web fragments (i.e. jars) are allowed to perform a ServletContainerInitializer
scan. When using this feature, the SpringServletContainerInitializer
can be enabled by adding "spring_web" to the list of named web fragments in
web.xml as follows:
<absolute-ordering> <name>some_web_fragment</name> <name>spring_web</name> </absolute-ordering>
WebApplicationInitializerWebApplicationInitializer SPI consists of just one method:
WebApplicationInitializer#onStartup(ServletContext). The signature is intentionally
quite similar to ServletContainerInitializer#onStartup(Set, ServletContext):
simply put, SpringServletContainerInitializer is responsible for instantiating
and delegating the ServletContext to any user-defined
WebApplicationInitializer implementations. It is then the responsibility of
each WebApplicationInitializer to do the actual work of initializing the
ServletContext. The exact process of delegation is described in detail in the
onStartup documentation below.
WebApplicationInitializer SPI. 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 runtimes, it remains the user's choice whether to make any
WebApplicationInitializer implementations available on the classpath.
If no WebApplicationInitializer types are detected, this container
initializer will have no effect.
Note that use of this container initializer and of WebApplicationInitializer
is not in any way "tied" to Spring MVC other than the fact that the types are shipped
in the spring-web module JAR. Rather, they can be considered general-purpose
in their ability to facilitate convenient code-based configuration of the
ServletContext. In other words, any servlet, listener, or filter may be
registered within a WebApplicationInitializer, not just Spring MVC-specific
components.
This class is neither designed for extension nor intended to be extended.
It should be considered an internal type, with WebApplicationInitializer
being the public-facing SPI.
WebApplicationInitializer Javadoc for examples and detailed usage
recommendations.
onStartup(Set, ServletContext), WebApplicationInitializer
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | onStartup(Set<Class<?>>
all implementations of
webAppInitializerClasses, ServletContext WebApplicationInitializer found on the application classpaththe servlet context to be initialized servletContext)Implements jakarta. ServletContext to any WebApplicationInitializer
implementations present on the application classpath.
|
| SpringServletContainerInitializer | back to summary |
|---|---|
| public SpringServletContainerInitializer() | |
| onStartup | back to summary |
|---|---|
| public void onStartup(Set<Class<?>> webAppInitializerClasses, ServletContext servletContext) throws ServletException Implements jakarta. Delegate the Because this class declares @ If no Assuming that one or more
| |