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:
org.springframework.web.WebApplicationInitializer

public abstract class AbstractAnnotationConfigDispatcherServletInitializer extends AbstractDispatcherServletInitializer
WebApplicationInitializer to register a DispatcherServlet and use Java-based Spring configuration.

Implementations are required to implement:

If an application context hierarchy is not required, applications may return all configuration via getRootConfigClasses() and return null from getServletConfigClasses().

Since:
3.2
Author:
Arjen Poutsma, Chris Beams
  • Constructor Details

    • AbstractAnnotationConfigDispatcherServletInitializer

      public AbstractAnnotationConfigDispatcherServletInitializer()
  • Method Details

    • createRootApplicationContext

      @Nullable protected org.springframework.web.context.WebApplicationContext createRootApplicationContext()

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

      Specified by:
      createRootApplicationContext in class org.springframework.web.context.AbstractContextLoaderInitializer
    • createServletApplicationContext

      protected org.springframework.web.context.WebApplicationContext createServletApplicationContext()
      Create a servlet application context to be provided to the DispatcherServlet.

      The returned context is delegated to Spring's 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
      See Also:
    • getRootConfigClasses

      @Nullable protected abstract Class<?>[] getRootConfigClasses()
      Specify @Configuration and/or @Component classes for the root application context.
      Returns:
      the configuration for the root application context, or null if creation and registration of a root context is not desired
    • getServletConfigClasses

      @Nullable protected abstract Class<?>[] getServletConfigClasses()
      Specify @Configuration and/or @Component classes for the Servlet application context.
      Returns:
      the configuration for the Servlet application context, or null if all configuration is specified through root config classes.