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

ConfigurableBeanFactory (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.beans.factory.config
Interface ConfigurableBeanFactory

All Superinterfaces:
BeanFactory, HierarchicalBeanFactory, SingletonBeanRegistry
All Known Subinterfaces:
ConfigurableListableBeanFactory
All Known Implementing Classes:
AbstractAutowireCapableBeanFactory, AbstractBeanFactory, DefaultListableBeanFactory, XmlBeanFactory

public interface ConfigurableBeanFactory
extends HierarchicalBeanFactory, SingletonBeanRegistry

Configuration interface to be implemented by most bean factories. Provides facilities to configure a bean factory, in addition to the bean factory client methods in the BeanFactory interface.

This bean factory interface is not meant to be used in normal application code: Stick to BeanFactory or ListableBeanFactory for typical needs. This extended interface is just meant to allow for framework-internal plug'n'play and for special access to bean factory configuration methods.

Since:
03.11.2003
Author:
Juergen Hoeller
See Also:
BeanFactory, ListableBeanFactory, ConfigurableListableBeanFactory

Field Summary
static String SCOPE_PROTOTYPE
          Scope identifier for the standard prototype scope: "prototype".
static String SCOPE_SINGLETON
          Scope identifier for the standard singleton scope: "singleton".
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Method Summary
 void addBeanPostProcessor(BeanPostProcessor beanPostProcessor)
          Add a new BeanPostProcessor that will get applied to beans created by this factory.
 void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar)
          Add a PropertyEditorRegistrar to be applied to all bean creation processes.
 void copyConfigurationFrom(ConfigurableBeanFactory otherFactory)
          Copy all relevant configuration from the given other factory.
 void destroyBean(String beanName, Object beanInstance)
          Destroy the given bean instance (usually a prototype instance obtained from this factory) according to its bean definition.
 void destroyScopedBean(String beanName)
          Destroy the specified scoped bean in the current target scope, if any.
 void destroySingletons()
          Destroy all singleton beans in this factory, including inner beans that have been registered as disposable.
 ClassLoader getBeanClassLoader()
          Return this factory's class loader for loading bean classes.
 int getBeanPostProcessorCount()
          Return the current number of registered BeanPostProcessors, if any.
 Scope getRegisteredScope(String scopeName)
          Return the Scope implementation for the given scope name, if any.
 String[] getRegisteredScopeNames()
          Return the names of all currently registered scopes.
 TypeConverter getTypeConverter()
          Obtain a type converter as used by this BeanFactory.
 boolean isCacheBeanMetadata()
          Return whether to cache bean metadata such as given bean definitions (in merged fashion) and resolved bean classes.
 boolean isCurrentlyInCreation(String beanName)
          Return whether the specified bean is currently in creation.
 void registerAlias(String beanName, String alias)
          Given a bean name, create an alias.
 void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor)
          Register the given custom property editor for all properties of the given type.
 void registerScope(String scopeName, Scope scope)
          Register the given scope, backed by the given Scope implementation.
 void setBeanClassLoader(ClassLoader beanClassLoader)
          Set the class loader to use for loading bean classes.
 void setCacheBeanMetadata(boolean cacheBeanMetadata)
          Set whether to cache bean metadata such as given bean definitions (in merged fashion) and resolved bean classes.
 void setParentBeanFactory(BeanFactory parentBeanFactory)
          Set the parent of this bean factory.
 
Methods inherited from interface org.springframework.beans.factory.HierarchicalBeanFactory
containsLocalBean, getParentBeanFactory
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch
 
Methods inherited from interface org.springframework.beans.factory.config.SingletonBeanRegistry
containsSingleton, getSingleton, getSingletonCount, getSingletonNames, registerSingleton
 

Field Detail

SCOPE_SINGLETON

static final String SCOPE_SINGLETON
Scope identifier for the standard singleton scope: "singleton". Custom scopes can be added via registerScope.

See Also:
registerScope(java.lang.String, org.springframework.beans.factory.config.Scope), Constant Field Values

SCOPE_PROTOTYPE

static final String SCOPE_PROTOTYPE
Scope identifier for the standard prototype scope: "prototype". Custom scopes can be added via registerScope.

See Also:
registerScope(java.lang.String, org.springframework.beans.factory.config.Scope), Constant Field Values
Method Detail

setParentBeanFactory

void setParentBeanFactory(BeanFactory parentBeanFactory)
                          throws IllegalStateException
Set the parent of this bean factory.

Note that the parent cannot be changed: It should only be set outside a constructor if it isn't available at the time of factory instantiation.

Parameters:
parentBeanFactory - the parent BeanFactory
Throws:
IllegalStateException - if this factory is already associated with a parent BeanFactory
See Also:
HierarchicalBeanFactory.getParentBeanFactory()

setBeanClassLoader

void setBeanClassLoader(ClassLoader beanClassLoader)
Set the class loader to use for loading bean classes. Default is the thread context class loader.

Note that this class loader will only apply to bean definitions that do not carry a resolved bean class yet. This is the case as of Spring 2.0 by default: Bean definitions only carry bean class names, to be resolved once the factory processes the bean definition.

Parameters:
beanClassLoader - the class loader to use, or null to suggest the default class loader

getBeanClassLoader

ClassLoader getBeanClassLoader()
Return this factory's class loader for loading bean classes.


setCacheBeanMetadata

void setCacheBeanMetadata(boolean cacheBeanMetadata)
Set whether to cache bean metadata such as given bean definitions (in merged fashion) and resolved bean classes. Default is on.

Turn this flag off to enable hot-refreshing of bean definition objects and in particular bean classes. If this flag is off, any creation of a bean instance will re-query the bean class loader for newly resolved classes.


isCacheBeanMetadata

boolean isCacheBeanMetadata()
Return whether to cache bean metadata such as given bean definitions (in merged fashion) and resolved bean classes.


addPropertyEditorRegistrar

void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar)
Add a PropertyEditorRegistrar to be applied to all bean creation processes.

Such a registrar creates new PropertyEditor instances and registers them on the given registry, fresh for each bean creation attempt. This avoids the need for synchronization on custom editors; hence, it is generally preferable to use this method instead of registerCustomEditor.

Parameters:
registrar - the PropertyEditorRegistrar to register
See Also:
registerCustomEditor(java.lang.Class, java.beans.PropertyEditor)

registerCustomEditor

void registerCustomEditor(Class requiredType,
                          PropertyEditor propertyEditor)
Register the given custom property editor for all properties of the given type. To be invoked during factory configuration.

Note that this method will register a shared custom editor instance; access to that instance will be synchronized for thread-safety. It is generally prefable to use addPropertyEditorRegistrar instead of this method, to avoid for the need for synchronization on custom editors.

Parameters:
requiredType - type of the property
propertyEditor - editor to register
See Also:
addPropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar)

getTypeConverter

TypeConverter getTypeConverter()
Obtain a type converter as used by this BeanFactory. This is typically a fresh instance for each call, since TypeConverters are usually not thread-safe.


addBeanPostProcessor

void addBeanPostProcessor(BeanPostProcessor beanPostProcessor)
Add a new BeanPostProcessor that will get applied to beans created by this factory. To be invoked during factory configuration.

Parameters:
beanPostProcessor - the bean processor to register

getBeanPostProcessorCount

int getBeanPostProcessorCount()
Return the current number of registered BeanPostProcessors, if any.


registerScope

void registerScope(String scopeName,
                   Scope scope)
Register the given scope, backed by the given Scope implementation.

Parameters:
scopeName - the scope identifier
scope - the backing Scope implementation

getRegisteredScopeNames

String[] getRegisteredScopeNames()
Return the names of all currently registered scopes.

This will only return the names of explicitly registered scopes. Built-in scopes such as "singleton" and "prototype" won't be exposed.

Returns:
the array of scope names, or an empty array if none
See Also:
registerScope(java.lang.String, org.springframework.beans.factory.config.Scope)

getRegisteredScope

Scope getRegisteredScope(String scopeName)
Return the Scope implementation for the given scope name, if any.

This will only return explicitly registered scopes. Built-in scopes such as "singleton" and "prototype" won't be exposed.

Parameters:
scopeName - the name of the scope
Returns:
the registered Scope implementation, or null if none
See Also:
registerScope(java.lang.String, org.springframework.beans.factory.config.Scope)

copyConfigurationFrom

void copyConfigurationFrom(ConfigurableBeanFactory otherFactory)
Copy all relevant configuration from the given other factory.

Should include all standard configuration settings as well as BeanPostProcessors, Scopes, and factory-specific internal settings. Should not include any metadata of actual bean definitions, such as BeanDefinition objects and bean name aliases.

Parameters:
otherFactory - the other BeanFactory to copy from

registerAlias

void registerAlias(String beanName,
                   String alias)
                   throws BeanDefinitionStoreException
Given a bean name, create an alias. We typically use this method to support names that are illegal within XML ids (used for bean names).

Typically invoked during factory configuration, but can also be used for runtime registration of aliases. Therefore, a factory implementation should synchronize alias access.

Parameters:
beanName - the canonical name of the bean
alias - the alias to be registered for the bean
Throws:
BeanDefinitionStoreException - if the alias is already in use

isCurrentlyInCreation

boolean isCurrentlyInCreation(String beanName)
Return whether the specified bean is currently in creation.

Parameters:
beanName - the name of the bean

destroyBean

void destroyBean(String beanName,
                 Object beanInstance)
Destroy the given bean instance (usually a prototype instance obtained from this factory) according to its bean definition.

Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.

Parameters:
beanName - the name of the bean definition
beanInstance - the bean instance to destroy

destroyScopedBean

void destroyScopedBean(String beanName)
Destroy the specified scoped bean in the current target scope, if any.

Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.

Parameters:
beanName - the name of the scoped bean

destroySingletons

void destroySingletons()
Destroy all singleton beans in this factory, including inner beans that have been registered as disposable. To be called on shutdown of a factory.

Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.


The Spring Framework

Copyright © 2002-2007 The Spring Framework.