Generic ApplicationContext implementation that holds a single internal
DefaultListableBeanFactory instance and does not assume a specific bean
definition format. Implements the BeanDefinitionRegistry interface to
allow for applying any bean definition readers to it.
Typical usage is to register a variety of bean definitions via the
BeanDefinitionRegistry interface and then call refresh to initialize
those beans with application context semantics (handling ApplicationContextAware,
auto-detecting 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. 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 ClassPathXmlApplicationContext
or FileSystemXmlApplicationContext, which are easier to set up - but less flexible,
as 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
XmlWebApplicationContext, implementing the extended WebApplicationContext interface.
For custom application context implementations that are supposed to read
special bean definition formats in a refreshable manner, consider deriving
from the AbstractRefreshableApplicationContext base class. For a corresponding
base class that pre-implements the extended WebApplicationContext interface,
consider AbstractRefreshableWebApplicationContext.
Typical usage is to register a variety of bean definitions via the BeanDefinitionRegistry interface and then call
refreshto initialize those beans with application context semantics (handling ApplicationContextAware, auto-detecting 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.
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 ClassPathXmlApplicationContext or FileSystemXmlApplicationContext, which are easier to set up - but less flexible, as 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 XmlWebApplicationContext, implementing the extended WebApplicationContext interface.For custom application context implementations that are supposed to read special bean definition formats in a refreshable manner, consider deriving from the AbstractRefreshableApplicationContext base class. For a corresponding base class that pre-implements the extended WebApplicationContext interface, consider AbstractRefreshableWebApplicationContext.