org.springframework.web.context

## Class AbstractContextLoaderInitializer

- java.lang.Object
- - org.springframework.web.context.AbstractContextLoaderInitializer

All Implemented Interfaces:
  WebApplicationInitializer

Direct Known Subclasses:
  AbstractDispatcherServletInitializer

    public abstract class AbstractContextLoaderInitializer
    extends Object
    implements 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(javax.servlet.ServletContext)`.

Since:
  3.2
Author:
  Arjen Poutsma, Chris Beams

### Field Summary

Fields
`protected Log` `logger` Logger available to subclasses.

### Constructor Summary

Constructors
Constructor and Description
`AbstractContextLoaderInitializer()`

### Method Summary

Methods
`protected abstract WebApplicationContext` `createRootApplicationContext()` Create the "root" application context to be provided to the `ContextLoaderListener`.
`void` `onStartup(ServletContext servletContext)` Configure the given `ServletContext` with any servlets, filters, listeners context-params and attributes necessary for initializing this web application.
`protected void` `registerContextLoaderListener(ServletContext servletContext)` Register a `ContextLoaderListener` against the given servlet context.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### logger

    protected final Log logger

Logger available to subclasses.

### Constructor Detail

#### AbstractContextLoaderInitializer

    public AbstractContextLoaderInitializer()

### Method Detail

#### onStartup

    public void onStartup(ServletContext servletContext)
                   throws ServletException

Description copied from interface: `WebApplicationInitializer`
Configure the given `ServletContext` with any servlets, filters, listeners context-params and attributes necessary for initializing this web application. See examples above.

Specified by:
  `onStartup` in interface `WebApplicationInitializer`
Parameters:
  `servletContext` - the `ServletContext` to initialize
Throws:
  `ServletException` - if any call against the given `ServletContext` throws a `ServletException`

#### registerContextLoaderListener

    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` - the servlet context to register the listener against

#### createRootApplicationContext

    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:
  the root application context, or `null` if a root context is not desired
See Also:
  `AbstractDispatcherServletInitializer`