类 ContextSingletonBeanFactoryLocator
- java.lang.Object
- org.springframework.beans.factory.access.SingletonBeanFactoryLocator
- org.springframework.context.access.ContextSingletonBeanFactoryLocator
- 所有已实现的接口:
BeanFactoryLocator
public class ContextSingletonBeanFactoryLocator extends SingletonBeanFactoryLocator
Variant of
SingletonBeanFactoryLocator
which creates its internal bean factory reference as anApplicationContext
instead of SingletonBeanFactoryLocator's simple BeanFactory. For almost all usage scenarios, this will not make a difference, since within that ApplicationContext or BeanFactory you are still free to define either BeanFactory or ApplicationContext instances. The main reason one would need to use this class is if bean post-processing (or other ApplicationContext specific features are needed in the bean reference definition itself).Note: This class uses classpath*:beanRefContext.xml as the default resource location for the bean factory reference definition files. It is not possible nor legal to share definitions with SingletonBeanFactoryLocator at the same time.
- 作者:
- Colin Sampaleanu, Juergen Hoeller
- 另请参阅:
SingletonBeanFactoryLocator
,DefaultLocatorFactory
字段概要
从类继承的字段 org.springframework.beans.factory.access.SingletonBeanFactoryLocator
logger
构造器概要
构造器 限定符 构造器 说明 protected
ContextSingletonBeanFactoryLocator(String resourceLocation)
Constructor which uses the specified name as the resource name of the definition file(s).
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 protected BeanFactory
createDefinition(String resourceLocation, String factoryKey)
Overrides the default method to create definition object as an ApplicationContext instead of the default BeanFactory.protected void
destroyDefinition(BeanFactory groupDef, String selector)
Overrides the default method to operate on an ApplicationContext, invokingConfigurableApplicationContext.close()
.static BeanFactoryLocator
getInstance()
Returns an instance which uses the default "classpath*:beanRefContext.xml", as the name of the definition file(s).static BeanFactoryLocator
getInstance(String selector)
Returns an instance which uses the specified selector, as the name of the definition file(s).protected void
initializeDefinition(BeanFactory groupDef)
Overrides the default method to refresh the ApplicationContext, invokingConfigurableApplicationContext.refresh()
.从类继承的方法 org.springframework.beans.factory.access.SingletonBeanFactoryLocator
useBeanFactory
构造器详细资料
ContextSingletonBeanFactoryLocator
protected ContextSingletonBeanFactoryLocator(String resourceLocation)
Constructor which uses the specified name as the resource name of the definition file(s).- 参数:
resourceLocation
- the Spring resource location to use (either a URL or a "classpath:" / "classpath*:" pseudo URL)
方法详细资料
getInstance
public static BeanFactoryLocator getInstance() throws BeansException
Returns an instance which uses the default "classpath*:beanRefContext.xml", as the name of the definition file(s). All resources returned by the current thread's context class loader'sgetResources
method with this name will be combined to create a definition, which is just a BeanFactory.- 返回:
- the corresponding BeanFactoryLocator instance
- 抛出:
BeansException
- in case of factory loading failure
getInstance
public static BeanFactoryLocator getInstance(String selector) throws BeansException
Returns an instance which uses the specified selector, as the name of the definition file(s). In the case of a name with a Spring "classpath*:" prefix, or with no prefix, which is treated the same, the current thread's context class loader'sgetResources
method will be called with this value to get all resources having that name. These resources will then be combined to form a definition. In the case where the name uses a Spring "classpath:" prefix, or a standard URL prefix, then only one resource file will be loaded as the definition.- 参数:
selector
- the location of the resource(s) which will be read and combined to form the definition for the BeanFactoryLocator instance. Any such files must form a valid ApplicationContext definition.- 返回:
- the corresponding BeanFactoryLocator instance
- 抛出:
BeansException
- in case of factory loading failure
createDefinition
protected BeanFactory createDefinition(String resourceLocation, String factoryKey)
Overrides the default method to create definition object as an ApplicationContext instead of the default BeanFactory. This does not affect what can actually be loaded by that definition.The default implementation simply builds a
ClassPathXmlApplicationContext
.- 覆盖:
createDefinition
在类中SingletonBeanFactoryLocator
- 参数:
resourceLocation
- the resource location for this factory groupfactoryKey
- the bean name of the factory to obtain- 返回:
- the corresponding BeanFactory reference
initializeDefinition
protected void initializeDefinition(BeanFactory groupDef)
Overrides the default method to refresh the ApplicationContext, invokingConfigurableApplicationContext.refresh()
.- 覆盖:
initializeDefinition
在类中SingletonBeanFactoryLocator
- 参数:
groupDef
- the factory returned bycreateDefinition()
destroyDefinition
protected void destroyDefinition(BeanFactory groupDef, String selector)
Overrides the default method to operate on an ApplicationContext, invokingConfigurableApplicationContext.close()
.- 覆盖:
destroyDefinition
在类中SingletonBeanFactoryLocator
- 参数:
groupDef
- the factory returned bycreateDefinition()
selector
- the resource location for this factory group