Top Description Constructors Methods
org.springframework.context.support

public Class FileSystemXmlApplicationContext

extends AbstractXmlApplicationContext
Class Inheritance
Imports
org.springframework.beans.BeansException, org.springframework.context.ApplicationContext, org.springframework.core.io.FileSystemResource, .Resource, org.springframework.lang.Nullable

Standalone XML application context, taking the context definition files from the file system or from URLs, interpreting plain paths as relative file system locations (e.g. "mydir/myfile.txt"). Useful for test harnesses as well as for standalone environments.

Note

Plain paths will always be interpreted as relative to the current VM working directory, even if they start with a slash. (This is consistent with the semantics in a Servlet container.) Use an explicit "file:" prefix to enforce an absolute file path.

The config location defaults can be overridden via getConfigLocations, Config locations can either denote concrete files like "/myfiles/context.xml" or Ant-style patterns like "/myfiles/*-context.xml" (see the org.springframework.util.AntPathMatcher 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.

This is a simple, one-stop shop convenience ApplicationContext. Consider using the GenericApplicationContext class in combination with an org.springframework.beans.factory.xml.XmlBeanDefinitionReader for more flexible context setup.

Authors
Rod Johnson, Juergen Hoeller
See Also
getResource, getResourceByPath, GenericApplicationContext

Constructor Summary

AccessConstructor and Description
public
FileSystemXmlApplicationContext()

Create a new FileSystemXmlApplicationContext for bean-style configuration.

public
FileSystemXmlApplicationContext(ApplicationContext
the parent context
parent
)

Create a new FileSystemXmlApplicationContext for bean-style configuration.

public
FileSystemXmlApplicationContext(String
file path
configLocation
)

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML file and automatically refreshing the context.

public
FileSystemXmlApplicationContext(String...
array of file paths
configLocations
)

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML files and automatically refreshing the context.

public
FileSystemXmlApplicationContext(String[]
array of file paths
configLocations
,
ApplicationContext
the parent context
parent
)

Create a new FileSystemXmlApplicationContext with the given parent, loading the definitions from the given XML files and automatically refreshing the context.

public
FileSystemXmlApplicationContext(String[]
array of file paths
configLocations
,
boolean
whether to automatically refresh the context, loading all bean definitions and creating all singletons. Alternatively, call refresh manually after further configuring the context.
refresh
)

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML files.

public
FileSystemXmlApplicationContext(String[]
array of file paths
configLocations
,
boolean
whether to automatically refresh the context, loading all bean definitions and creating all singletons. Alternatively, call refresh manually after further configuring the context.
refresh
,
ApplicationContext
the parent context
parent
)

Create a new FileSystemXmlApplicationContext with the given parent, loading the definitions from the given XML files.

Method Summary

Modifier and TypeMethod and Description
protected Resource

Returns:

the Resource handle
getResourceByPath
(String
the path to the resource
path
)

Overrides org.springframework.core.io.DefaultResourceLoader.getResourceByPath.

Resolve resource paths as file system paths.

Inherited from org.springframework.context.support.AbstractXmlApplicationContext:
getConfigResourcesinitBeanDefinitionReaderloadBeanDefinitionsloadBeanDefinitionssetValidating

Constructor Detail

FileSystemXmlApplicationContextback to summary
public FileSystemXmlApplicationContext()

Create a new FileSystemXmlApplicationContext for bean-style configuration.

See Also
setConfigLocation, setConfigLocations, afterPropertiesSet()
FileSystemXmlApplicationContextback to summary
public FileSystemXmlApplicationContext(ApplicationContext parent)

Create a new FileSystemXmlApplicationContext for bean-style configuration.

Parameters
parent:ApplicationContext

the parent context

See Also
setConfigLocation, setConfigLocations, afterPropertiesSet()
FileSystemXmlApplicationContextback to summary
public FileSystemXmlApplicationContext(String configLocation) throws BeansException

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML file and automatically refreshing the context.

Parameters
configLocation:String

file path

Exceptions
BeansException:
if context creation failed
FileSystemXmlApplicationContextback to summary
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML files and automatically refreshing the context.

Parameters
configLocations:String[]

array of file paths

Exceptions
BeansException:
if context creation failed
FileSystemXmlApplicationContextback to summary
public FileSystemXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException

Create a new FileSystemXmlApplicationContext with the given parent, loading the definitions from the given XML files and automatically refreshing the context.

Parameters
configLocations:String[]

array of file paths

parent:ApplicationContext

the parent context

Exceptions
BeansException:
if context creation failed
FileSystemXmlApplicationContextback to summary
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML files.

Parameters
configLocations:String[]

array of file paths

refresh:boolean

whether to automatically refresh the context, loading all bean definitions and creating all singletons. Alternatively, call refresh manually after further configuring the context.

Exceptions
BeansException:
if context creation failed
See Also
refresh()
FileSystemXmlApplicationContextback to summary
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) throws BeansException

Create a new FileSystemXmlApplicationContext with the given parent, loading the definitions from the given XML files.

Parameters
configLocations:String[]

array of file paths

refresh:boolean

whether to automatically refresh the context, loading all bean definitions and creating all singletons. Alternatively, call refresh manually after further configuring the context.

parent:ApplicationContext

the parent context

Exceptions
BeansException:
if context creation failed
See Also
refresh()

Method Detail

getResourceByPathback to summary
protected Resource getResourceByPath(String path)

Overrides org.springframework.core.io.DefaultResourceLoader.getResourceByPath.

Resolve resource paths as file system paths.

Note

Even if a given path starts with a slash, it will get interpreted as relative to the current VM working directory. This is consistent with the semantics in a Servlet container.

Parameters
path:String

the path to the resource

Returns:Resource

the Resource handle

Annotations
@Override
See Also
org.springframework.web.context.support.XmlWebApplicationContext#getResourceByPath