Generic ApplicationContext implementation that holds a single internal {@link org.springframework.beans.factory.support.DefaultListableBeanFactory}instance and does not assume a specific bean definition format. Implements the {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}interface in order to allow for applying any bean definition readers to it.
Typical usage is to register a variety of bean definitions via the {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}interface and then call {@link #refresh()} to initialize those beanswith application context semantics (handling {@link org.springframework.context.ApplicationContextAware}, auto-detecting {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor BeanFactoryPostProcessors}, etc).
In contrast to other ApplicationContext implementations that create a new internal BeanFactory instance for each refresh, the internal BeanFactory of this context is available right from the start, to be able to register bean definitions on it. {@link #refresh()} may only be called once.
Usage example:
GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml")); PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(ctx); propReader.loadBeanDefinitions(new ClassPathResource("otherBeans.properties")); ctx.refresh(); MyBean myBean = (MyBean) ctx.getBean("myBean"); ...
For the typical case of XML bean definitions, simply use {@link ClassPathXmlApplicationContext} or {@link FileSystemXmlApplicationContext}, which are easier to set up - but less flexible, since you can just use standard resource locations for XML bean definitions, rather than mixing arbitrary bean definition formats. The equivalent in a web environment is {@link org.springframework.web.context.support.XmlWebApplicationContext}.
For custom application context implementations that are supposed to read special bean definition formats in a refreshable manner, consider deriving from the {@link AbstractRefreshableApplicationContext} base class.
@author Juergen Hoeller
@since 1.1.2
@see #registerBeanDefinition
@see #refresh()
@see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
@see org.springframework.beans.factory.support.PropertiesBeanDefinitionReader