org.springframework.web.context
Class ContextLoader


public class ContextLoader

Performs the actual initialization work for the root application context. Called by ContextLoaderListener and ContextLoaderServlet.

Regards a "contextClass" parameter at the web.xml context-param level, falling back to the default context class (XmlWebApplicationContext) if not found. With the default ContextLoader, a context class needs to implement ConfigurableWebApplicationContext.

Passes a "contextConfigLocation" context-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "applicationContext1.xml, applicationContext2.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 earlier 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.

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

Field Summary
 final static StringCONFIG_LOCATION_PARAM
          Name of servlet context parameter that can specify the config location for the root context, falling back to DEFAULT_CONFIG_LOCATION.
 final static StringCONTEXT_CLASS_PARAM
          Config param for the root WebApplicationContext implementation class to use: "contextClass"
 final static ClassDEFAULT_CONTEXT_CLASS
          Default context class for ContextLoader.

Method Summary
 voidcloseWebApplicationContext(ServletContext servletContext)
          Close Spring's web application context for the given servlet context.
 WebApplicationContextinitWebApplicationContext(ServletContext servletContext)
          Initialize Spring's web application context for the given servlet context, regarding the "contextClass" and "contextConfigLocation" context-params.

Field Detail

CONFIG_LOCATION_PARAM

public final static String CONFIG_LOCATION_PARAM
Name of servlet context parameter that can specify the config location for the root context, falling back to DEFAULT_CONFIG_LOCATION.

CONTEXT_CLASS_PARAM

public final static String CONTEXT_CLASS_PARAM
Config param for the root WebApplicationContext implementation class to use: "contextClass"

DEFAULT_CONTEXT_CLASS

public final static Class DEFAULT_CONTEXT_CLASS
Default context class for ContextLoader.
See Also:
XmlWebApplicationContext
Method Detail

closeWebApplicationContext

public void closeWebApplicationContext(ServletContext servletContext)
throws org.springframework.context.ApplicationContextException
Close Spring's web application context for the given servlet context.
Parameters:
servletContext - current servlet context

initWebApplicationContext

public WebApplicationContext initWebApplicationContext(ServletContext servletContext)
throws org.springframework.beans.BeansException
Initialize Spring's web application context for the given servlet context, regarding the "contextClass" and "contextConfigLocation" context-params.
Parameters:
servletContext - current servlet context
Returns: the new WebApplicationContext
Throws:
BeansException - if the context couldn't be initialized
See Also:
CONTEXT_CLASS_PARAM, CONFIG_LOCATION_PARAM

Association Links

to Class java.lang.String

Config param for the root WebApplicationContext implementation class to use: "contextClass"

to Class java.lang.Class

Default context class for ContextLoader.

see org.springframework.web.context.support.XmlWebApplicationContext

to Class java.lang.String

Name of servlet context parameter that can specify the config location for the root context, falling back to DEFAULT_CONFIG_LOCATION.