|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.core.io.DefaultResourceLoader org.springframework.context.support.AbstractApplicationContext org.springframework.context.support.GenericApplicationContext
Generic ApplicationContext implementation which does not assume a specific bean definition format. Holds an internal DefaultListableBeanFactory, and implements the BeanDefinitionRegistry interface to allow for applying 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.
registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)
,
AbstractApplicationContext.refresh()
,
BeanDefinitionRegistry
,
DefaultListableBeanFactory
,
ClassPathXmlApplicationContext
,
FileSystemXmlApplicationContext
Field Summary |
Fields inherited from class org.springframework.context.support.AbstractApplicationContext |
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME |
Fields inherited from interface org.springframework.beans.factory.BeanFactory |
FACTORY_BEAN_PREFIX |
Fields inherited from interface org.springframework.core.io.ResourceLoader |
CLASSPATH_URL_PREFIX |
Constructor Summary | |
GenericApplicationContext()
Create a new GenericApplicationContext. |
|
GenericApplicationContext(ApplicationContext parent)
Create a new GenericApplicationContext with the given parent. |
Method Summary | |
BeanDefinition |
getBeanDefinition(String name)
Return the BeanDefinition for the given bean name. |
ConfigurableListableBeanFactory |
getBeanFactory()
Return the single internal BeanFactory held by this context. |
DefaultListableBeanFactory |
getDefaultListableBeanFactory()
Return the underlying bean factory of this context, available for registering bean definitions. |
protected void |
refreshBeanFactory()
Do nothing: We hold a single internal BeanFactory and rely on callers to register beans through our public methods respectively the BeanFactory's. |
void |
registerAlias(String name,
String alias)
Given a bean name, create an alias. |
void |
registerBeanDefinition(String name,
BeanDefinition beanDefinition)
Register a new bean definition with this registry. |
Methods inherited from class org.springframework.context.support.AbstractApplicationContext |
addBeanFactoryPostProcessor, addListener, close, containsBean, containsBeanDefinition, getAliases, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeansOfType, getBeansOfType, getDisplayName, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getStartupDate, getType, isSingleton, onRefresh, postProcessBeanFactory, publishEvent, refresh, setDisplayName, setParent, toString |
Methods inherited from class org.springframework.core.io.DefaultResourceLoader |
getClassLoader, getResource, getResourceByPath |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.springframework.beans.factory.support.BeanDefinitionRegistry |
containsBeanDefinition, getAliases, getBeanDefinitionCount, getBeanDefinitionNames |
Methods inherited from interface org.springframework.core.io.ResourceLoader |
getResource |
Constructor Detail |
public GenericApplicationContext()
registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)
,
AbstractApplicationContext.refresh()
public GenericApplicationContext(ApplicationContext parent)
parent
- the parent application contextregisterBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)
,
AbstractApplicationContext.refresh()
Method Detail |
protected void refreshBeanFactory() throws IllegalStateException
refreshBeanFactory
in class AbstractApplicationContext
IllegalStateException
- if already initialized and multiple refresh
attempts are not supportedregisterBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)
public ConfigurableListableBeanFactory getBeanFactory()
getBeanFactory
in interface ConfigurableApplicationContext
getBeanFactory
in class AbstractApplicationContext
AbstractApplicationContext.refresh()
public DefaultListableBeanFactory getDefaultListableBeanFactory()
NOTE: You need to call refresh
to initialize the
bean factory and its contained beans with application context semantics
(auto-detecting BeanFactoryPostProcessors, etc)
AbstractApplicationContext.refresh()
public BeanDefinition getBeanDefinition(String name) throws BeansException
BeanDefinitionRegistry
getBeanDefinition
in interface BeanDefinitionRegistry
name
- name of the bean to find a definition for
BeansException
- in case of errorspublic void registerBeanDefinition(String name, BeanDefinition beanDefinition) throws BeansException
BeanDefinitionRegistry
registerBeanDefinition
in interface BeanDefinitionRegistry
name
- the name of the bean instance to registerbeanDefinition
- definition of the bean instance to register
BeansException
- if the bean definition is invalidRootBeanDefinition
,
ChildBeanDefinition
public void registerAlias(String name, String alias) throws BeansException
BeanDefinitionRegistry
registerAlias
in interface BeanDefinitionRegistry
name
- the name of the beanalias
- alias that will behave the same as the bean name
BeansException
- if the alias is already in use
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |