spring-framework / org.springframework.context.support / ClassPathXmlApplicationContext

ClassPathXmlApplicationContext

open class ClassPathXmlApplicationContext : AbstractXmlApplicationContext

Standalone XML application context, taking the context definition files from the class path, interpreting plain paths as class path resource names that include the package path (e.g. "mypackage/myresource.txt"). Useful for test harnesses as well as for application contexts embedded within JARs.

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.

Author
Rod Johnson

Author
Juergen Hoeller

See Also
#getResource#getResourceByPathGenericApplicationContext

Constructors

<init>

ClassPathXmlApplicationContext()
ClassPathXmlApplicationContext(parent: ApplicationContext)

Create a new ClassPathXmlApplicationContext for bean-style configuration.

ClassPathXmlApplicationContext(configLocation: String)

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

ClassPathXmlApplicationContext(vararg configLocations: String)
ClassPathXmlApplicationContext(paths: Array<String>, clazz: Class<*>)

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

ClassPathXmlApplicationContext(configLocations: Array<String>, parent: ApplicationContext)
ClassPathXmlApplicationContext(paths: Array<String>, clazz: Class<*>, parent: ApplicationContext)

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

ClassPathXmlApplicationContext(configLocations: Array<String>, refresh: Boolean)

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

ClassPathXmlApplicationContext(configLocations: Array<String>, refresh: Boolean, parent: ApplicationContext)

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

ClassPathXmlApplicationContext(path: String, clazz: Class<*>)

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

This is a convenience method to load class path resources relative to a given Class. For full flexibility, consider using a GenericApplicationContext with an XmlBeanDefinitionReader and a ClassPathResource argument.

Inherited Functions

setValidating

open fun setValidating(validating: Boolean): Unit

Set whether to use XML validation. Default is true.