org.springframework.web.servlet.support

## Class AbstractAnnotationConfigDispatcherServletInitializer

- java.lang.Object
- - org.springframework.web.context.AbstractContextLoaderInitializer
  - - org.springframework.web.servlet.support.AbstractDispatcherServletInitializer
    - - org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer

All Implemented Interfaces:
  WebApplicationInitializer

    public abstract class AbstractAnnotationConfigDispatcherServletInitializer
    extends AbstractDispatcherServletInitializer

Base class for `WebApplicationInitializer` implementations that register a `DispatcherServlet` configured with annotated classes, e.g. Spring's `@Configuration` classes.

Concrete implementations are required to implement `getRootConfigClasses()`, `getServletConfigClasses()`, as well as `AbstractDispatcherServletInitializer.getServletMappings()`. Further template and customization methods are provided by `AbstractDispatcherServletInitializer`.

Since:
  3.2
Author:
  Arjen Poutsma, Chris Beams

### Field Summary

### Fields inherited from class org.springframework.web.servlet.support.AbstractDispatcherServletInitializer

`DEFAULT_SERVLET_NAME`

### Fields inherited from class org.springframework.web.context.AbstractContextLoaderInitializer

`logger`

### Constructor Summary

Constructors
Constructor and Description
`AbstractAnnotationConfigDispatcherServletInitializer()`

### Method Summary

Methods
`protected WebApplicationContext` `createRootApplicationContext()` Create the "root" application context to be provided to the `ContextLoaderListener`.
`protected WebApplicationContext` `createServletApplicationContext()` Create a servlet application context to be provided to the `DispatcherServlet`.
`protected abstract Class<?>[]` `getRootConfigClasses()` Specify `@Configuration` and/or `@Component` classes to be provided to the root application context.
`protected abstract Class<?>[]` `getServletConfigClasses()` Specify `@Configuration` and/or `@Component` classes to be provided to the dispatcher servlet application context.

### Methods inherited from class org.springframework.web.servlet.support.AbstractDispatcherServletInitializer

`customizeRegistration, getServletFilters, getServletMappings, getServletName, isAsyncSupported, onStartup, registerDispatcherServlet, registerServletFilter`

### Methods inherited from class org.springframework.web.context.AbstractContextLoaderInitializer

`registerContextLoaderListener`

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

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

### Constructor Detail

#### AbstractAnnotationConfigDispatcherServletInitializer

    public AbstractAnnotationConfigDispatcherServletInitializer()

### Method Detail

#### createRootApplicationContext

    protected 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.

This implementation creates an `AnnotationConfigWebApplicationContext`, providing it the annotated classes returned by `getRootConfigClasses()`. Returns `null` if `getRootConfigClasses()` returns `null`.

Specified by:
  `createRootApplicationContext` in class `AbstractContextLoaderInitializer`
Returns:
  the root application context, or `null` if a root context is not desired
See Also:
  `AbstractDispatcherServletInitializer`

#### createServletApplicationContext

    protected WebApplicationContext createServletApplicationContext()

Create a servlet application context to be provided to the `DispatcherServlet`.

The returned context is delegated to Spring's `DispatcherServlet.DispatcherServlet(WebApplicationContext)` As such, it typically contains controllers, view resolvers, locale resolvers, and other web-related beans.

This implementation creates an `AnnotationConfigWebApplicationContext`, providing it the annotated classes returned by `getServletConfigClasses()`.

Specified by:
  `createServletApplicationContext` in class `AbstractDispatcherServletInitializer`
Throws:
  `IllegalArgumentException` - if `getServletConfigClasses()` returns empty or `null`
See Also:
  `AbstractDispatcherServletInitializer.registerDispatcherServlet(ServletContext)`

#### getRootConfigClasses

    protected abstract Class<?>[] getRootConfigClasses()

Specify `@Configuration` and/or `@Component` classes to be provided to the root application context.

Returns:
  the configuration classes for the root application context, or `null` if creation and registration of a root context is not desired

#### getServletConfigClasses

    protected abstract Class<?>[] getServletConfigClasses()

Specify `@Configuration` and/or `@Component` classes to be provided to the dispatcher servlet application context.

Returns:
  the configuration classes for the dispatcher servlet application context (may not be empty or `null`).