站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.1.0 API 文档英文版

ContextSingletonBeanFactoryLocator (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版


The Spring Framework

org.springframework.context.access
Class ContextSingletonBeanFactoryLocator

java.lang.Object
  extended by org.springframework.beans.factory.access.SingletonBeanFactoryLocator
      extended by org.springframework.context.access.ContextSingletonBeanFactoryLocator
All Implemented Interfaces:
BeanFactoryLocator

public class ContextSingletonBeanFactoryLocator
extends SingletonBeanFactoryLocator

Variant of SingletonBeanFactoryLocator which creates its internal bean factory reference as an ApplicationContext 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.

Author:
Colin Sampaleanu, Juergen Hoeller
See Also:
SingletonBeanFactoryLocator, DefaultLocatorFactory

Field Summary
 
Fields inherited from class org.springframework.beans.factory.access.SingletonBeanFactoryLocator
logger
 
Constructor Summary
protected ContextSingletonBeanFactoryLocator(String resourceLocation)
          Constructor which uses the the specified name as the resource name of the definition file(s).
 
Method Summary
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, invoking ConfigurableApplicationContext.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 the specified selector, as the name of the definition file(s).
protected  void initializeDefinition(BeanFactory groupDef)
          Overrides the default method to refresh the ApplicationContext, invoking ConfigurableApplicationContext.refresh().
 
Methods inherited from class org.springframework.beans.factory.access.SingletonBeanFactoryLocator
useBeanFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextSingletonBeanFactoryLocator

protected ContextSingletonBeanFactoryLocator(String resourceLocation)
Constructor which uses the the specified name as the resource name of the definition file(s).

Parameters:
resourceLocation - the Spring resource location to use (either a URL or a "classpath:" / "classpath*:" pseudo URL)
Method Detail

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's getResources method with this name will be combined to create a definition, which is just a BeanFactory.

Returns:
the corresponding BeanFactoryLocator instance
Throws:
BeansException - in case of factory loading failure

getInstance

public static BeanFactoryLocator getInstance(String selector)
                                      throws BeansException
Returns an instance which uses the 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's getResources 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.

Parameters:
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.
Returns:
the corresponding BeanFactoryLocator instance
Throws:
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.

Overrides:
createDefinition in class SingletonBeanFactoryLocator
Parameters:
resourceLocation - the resource location for this factory group
factoryKey - the bean name of the factory to obtain
Returns:
the corresponding BeanFactory reference

initializeDefinition

protected void initializeDefinition(BeanFactory groupDef)
Overrides the default method to refresh the ApplicationContext, invoking ConfigurableApplicationContext.refresh().

Overrides:
initializeDefinition in class SingletonBeanFactoryLocator
Parameters:
groupDef - the factory returned by createDefinition()

destroyDefinition

protected void destroyDefinition(BeanFactory groupDef,
                                 String selector)
Overrides the default method to operate on an ApplicationContext, invoking ConfigurableApplicationContext.close().

Overrides:
destroyDefinition in class SingletonBeanFactoryLocator
Parameters:
groupDef - the factory returned by createDefinition()
selector - the resource location for this factory group

The Spring Framework

Copyright © 2002-2007 The Spring Framework.