Top Description Fields Constructors Methods
org.springframework.web.context

public abstract Class AbstractContextLoaderInitializer

extends Object
implements WebApplicationInitializer
Class Inheritance
All Implemented Interfaces
org.springframework.web.WebApplicationInitializer
Imports
jakarta.servlet.ServletContext, .ServletException, org.apache.commons.logging.Log, .LogFactory, org.springframework.context.ApplicationContextInitializer, org.springframework.lang.Nullable, org.springframework.web.WebApplicationInitializer

Convenient base class for WebApplicationInitializer implementations that register a ContextLoaderListener in the servlet context.

The only method required to be implemented by subclasses is createRootApplicationContext(), which gets invoked from registerContextLoaderListener(ServletContext).

Authors
Arjen Poutsma, Chris Beams, Juergen Hoeller
Since
3.2

Field Summary

Modifier and TypeField and Description
protected final Log
logger

Logger available to subclasses.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected abstract WebApplicationContext

Returns:

the root application context, or null if a root context is not desired
createRootApplicationContext
()

Create the "root" application context to be provided to the ContextLoaderListener.

protected ApplicationContextInitializer<?>[]
getRootApplicationContextInitializers()

Specify application context initializers to be applied to the root application context that the ContextLoaderListener is being created with.

public void
onStartup(ServletContext
the ServletContext to initialize
servletContext
)

Implements org.springframework.web.WebApplicationInitializer.onStartup.

Configure the given ServletContext with any servlets, filters, listeners context-params and attributes necessary for initializing this web application.

protected void
registerContextLoaderListener(ServletContext
the servlet context to register the listener against
servletContext
)

Register a ContextLoaderListener against the given servlet context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
protected final Log logger

Logger available to subclasses.

Constructor Detail

AbstractContextLoaderInitializerback to summary
public AbstractContextLoaderInitializer()

Method Detail

createRootApplicationContextback to summary
protected abstract WebApplicationContext createRootApplicationContext()

Create the "root" application context to be provided to the ContextLoaderListener.

The returned context is delegated to ContextLoaderListener#ContextLoaderListener(WebApplicationContext) and will be established as the parent context for any DispatcherServlet application contexts. As such, it typically contains middle-tier services, data sources, etc.

Returns:WebApplicationContext

the root application context, or null if a root context is not desired

Annotations
@Nullable
See Also
org.springframework.web.servlet.support.AbstractDispatcherServletInitializer
getRootApplicationContextInitializersback to summary
protected ApplicationContextInitializer<?>[] getRootApplicationContextInitializers()

Specify application context initializers to be applied to the root application context that the ContextLoaderListener is being created with.

Annotations
@Nullable
Since
4.2
See Also
createRootApplicationContext(), ContextLoaderListener#setContextInitializers
onStartupback to summary
public void onStartup(ServletContext servletContext) throws ServletException

Implements org.springframework.web.WebApplicationInitializer.onStartup.

Doc from org.springframework.web.WebApplicationInitializer.onStartup.

Configure the given ServletContext with any servlets, filters, listeners context-params and attributes necessary for initializing this web application. See examples above.

Parameters
servletContext:ServletContext

the ServletContext to initialize

Annotations
@Override
Exceptions
ServletException:
if any call against the given ServletContext throws a ServletException
registerContextLoaderListenerback to summary
protected void registerContextLoaderListener(ServletContext servletContext)

Register a ContextLoaderListener against the given servlet context. The ContextLoaderListener is initialized with the application context returned from the createRootApplicationContext() template method.

Parameters
servletContext:ServletContext

the servlet context to register the listener against