org.springframework.web.context

Class ContextLoader

  • java.lang.Object
    • org.springframework.web.context.ContextLoader
  • Direct Known Subclasses:
    ContextLoaderListener


    public class ContextLoader
    extends java.lang.Object
    Performs the actual initialization work for the root application context. Called by ContextLoaderListener.

    Looks for a "contextClass" parameter at the web.xml context-param level to specify the context class type, falling back to XmlWebApplicationContext if not found. With the default ContextLoader implementation, any context class specified needs to implement the ConfigurableWebApplicationContext interface.

    Processes a "contextConfigLocation" context-param and passes its value to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, e.g. "WEB-INF/applicationContext1.xml, WEB-INF/applicationContext2.xml". Ant-style path patterns are supported as well, e.g. "WEB-INF/*Context.xml,WEB-INF/spring*.xml" or "WEB-INF/**/*Context.xml". If not explicitly specified, the context implementation is supposed to use a default location (with XmlWebApplicationContext: "/WEB-INF/applicationContext.xml").

    Note: In case of multiple config locations, later bean definitions will override ones defined in previously loaded files, at least when using one of Spring's default ApplicationContext implementations. This can be leveraged to deliberately override certain bean definitions via an extra XML file.

    Above and beyond loading the root application context, this class can optionally load or obtain and hook up a shared parent context to the root application context. See the loadParentContext(ServletContext) method for more information.

    As of Spring 3.1, ContextLoader supports injecting the root web application context via the ContextLoader(WebApplicationContext) constructor, allowing for programmatic configuration in Servlet 3.0+ environments. See WebApplicationInitializer for usage examples.

    Since:
    17.02.2003
    Author:
    Juergen Hoeller, Colin Sampaleanu, Sam Brannen
    See Also:
    ContextLoaderListener, ConfigurableWebApplicationContext, XmlWebApplicationContext