Top Description Fields Constructors Methods
org.springframework.web.context.support

public Class XmlWebApplicationContext

extends AbstractRefreshableWebApplicationContext
Class Inheritance
Imports
java.io.IOException, org.springframework.beans.BeansException, org.springframework.beans.factory.support.DefaultListableBeanFactory, org.springframework.beans.factory.xml.ResourceEntityResolver, .XmlBeanDefinitionReader

Deprecated

as a consequence of AbstractRefreshableWebApplicationContext being deprecated. See corresponding docs for further information.

org.springframework.web.context.WebApplicationContext implementation which takes its configuration from XML documents, understood by an org.springframework.beans.factory.xml.XmlBeanDefinitionReader. This is essentially the equivalent of org.springframework.context.support.GenericXmlApplicationContext for a web environment.

By default, the configuration will be taken from "/WEB-INF/applicationContext.xml" for the root context, and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").

The config location defaults can be overridden via the "contextConfigLocation" context-param of org.springframework.web.context.ContextLoader and servlet init-param of org.springframework.web.servlet.FrameworkServlet. Config locations can either denote concrete files like "/WEB-INF/context.xml" or Ant-style patterns like "/WEB-INF/*-context.xml" (see org.springframework.util.PathMatcher javadoc for pattern details).

Note

In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra XML file.

For a WebApplicationContext that reads in a different bean definition format, create an analogous subclass of AbstractRefreshableWebApplicationContext. Such a context implementation can be specified as "contextClass" context-param for ContextLoader or "contextClass" init-param for FrameworkServlet.

Authors
Rod Johnson, Juergen Hoeller
See Also
setNamespace, setConfigLocations, org.springframework.beans.factory.xml.XmlBeanDefinitionReader, org.springframework.web.context.ContextLoader#initWebApplicationContext, org.springframework.web.servlet.FrameworkServlet#initWebApplicationContext

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_CONFIG_LOCATION

Default config location for the root context.

public static final String
DEFAULT_CONFIG_LOCATION_PREFIX

Default prefix for building a config location for a namespace.

public static final String
DEFAULT_CONFIG_LOCATION_SUFFIX

Default suffix for building a config location for a namespace.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected String[]
getDefaultConfigLocations()

Overrides org.springframework.context.support.AbstractRefreshableConfigApplicationContext.getDefaultConfigLocations.

The default location for the root context is "/WEB-INF/applicationContext.xml", and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").
protected void
initBeanDefinitionReader(XmlBeanDefinitionReader
the bean definition reader used by this context
beanDefinitionReader
)

Initialize the bean definition reader used for loading the bean definitions of this context.

protected void
loadBeanDefinitions(DefaultListableBeanFactory
the bean factory to load bean definitions into
beanFactory
)

Implements abstract org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

Loads the bean definitions via an XmlBeanDefinitionReader.
protected void
loadBeanDefinitions(XmlBeanDefinitionReader reader)

Load the bean definitions with the given XmlBeanDefinitionReader.

Inherited from org.springframework.web.context.support.AbstractRefreshableWebApplicationContext:
createEnvironmentgetApplicationNamegetConfigLocationsgetNamespacegetResourceByPathgetResourcePatternResolvergetServletConfiggetServletContextgetThemeinitPropertySourcesonRefreshpostProcessBeanFactorysetNamespacesetServletConfigsetServletContext

Field Detail

DEFAULT_CONFIG_LOCATIONback to summary
public static final String DEFAULT_CONFIG_LOCATION

Default config location for the root context.

DEFAULT_CONFIG_LOCATION_PREFIXback to summary
public static final String DEFAULT_CONFIG_LOCATION_PREFIX

Default prefix for building a config location for a namespace.

DEFAULT_CONFIG_LOCATION_SUFFIXback to summary
public static final String DEFAULT_CONFIG_LOCATION_SUFFIX

Default suffix for building a config location for a namespace.

Constructor Detail

XmlWebApplicationContextback to summary
public XmlWebApplicationContext()

Method Detail

getDefaultConfigLocationsback to summary
protected String[] getDefaultConfigLocations()

Overrides org.springframework.context.support.AbstractRefreshableConfigApplicationContext.getDefaultConfigLocations.

The default location for the root context is "/WEB-INF/applicationContext.xml", and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").

Returns:String[]

Doc from org.springframework.context.support.AbstractRefreshableConfigApplicationContext.getDefaultConfigLocations.

an array of default config locations, if any

Annotations
@Override
initBeanDefinitionReaderback to summary
protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader)

Initialize the bean definition reader used for loading the bean definitions of this context. Default implementation is empty.

Can be overridden in subclasses, e.g. for turning off XML validation or using a different XmlBeanDefinitionParser implementation.

Parameters
beanDefinitionReader:XmlBeanDefinitionReader

the bean definition reader used by this context

See Also
org.springframework.beans.factory.xml.XmlBeanDefinitionReader#setValidationMode, org.springframework.beans.factory.xml.XmlBeanDefinitionReader#setDocumentReaderClass
loadBeanDefinitionsback to summary
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException

Implements abstract org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

Loads the bean definitions via an XmlBeanDefinitionReader.

Parameters
beanFactory:DefaultListableBeanFactory

Doc from org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

the bean factory to load bean definitions into

Annotations
@Override
Exceptions
BeansException:

Doc from org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

if parsing of the bean definitions failed

IOException:

Doc from org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

if loading of bean definition files failed

See Also
org.springframework.beans.factory.xml.XmlBeanDefinitionReader, initBeanDefinitionReader, loadBeanDefinitions
loadBeanDefinitionsback to summary
protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws IOException

Load the bean definitions with the given XmlBeanDefinitionReader.

The lifecycle of the bean factory is handled by the refreshBeanFactory method; therefore this method is just supposed to load and/or register bean definitions.

Delegates to a ResourcePatternResolver for resolving location patterns into Resource instances.

Exceptions
IOException:
if the required XML document isn't found
See Also
refreshBeanFactory, getConfigLocations, getResources, getResourcePatternResolver