Top Description Fields Methods
org.springframework.beans.factory.config

public Interface ConfigurableBeanFactory

extends HierarchicalBeanFactory, SingletonBeanRegistry
Known Direct Subinterfaces
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
Known Direct Implementers
org.springframework.beans.factory.support.AbstractBeanFactory
Imports
java.beans.PropertyEditor, org.springframework.beans.PropertyEditorRegistrar, .PropertyEditorRegistry, .TypeConverter, org.springframework.beans.factory.BeanDefinitionStoreException, .BeanFactory, .HierarchicalBeanFactory, .NoSuchBeanDefinitionException, org.springframework.core.convert.ConversionService, org.springframework.core.metrics.ApplicationStartup, org.springframework.lang.Nullable, org.springframework.util.StringValueResolver

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 org.springframework.beans.factory.BeanFactory interface.

This bean factory interface is not meant to be used in normal application code: Stick to org.springframework.beans.factory.BeanFactory or org.springframework.beans.factory.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.

Author
Juergen Hoeller
Since
03.11.2003
See Also
org.springframework.beans.factory.BeanFactory, org.springframework.beans.factory.ListableBeanFactory, ConfigurableListableBeanFactory

Field Summary

Modifier and TypeField and Description
public static final String
SCOPE_PROTOTYPE

Scope identifier for the standard prototype scope: prototype.

public static final String
SCOPE_SINGLETON

Scope identifier for the standard singleton scope: singleton.

Method Summary

Modifier and TypeMethod and Description
public void
addBeanPostProcessor(BeanPostProcessor
the post-processor to register
beanPostProcessor
)

Add a new BeanPostProcessor that will get applied to beans created by this factory.

public void
addEmbeddedValueResolver(StringValueResolver
the String resolver to apply to embedded values
valueResolver
)

Add a String resolver for embedded values such as annotation attributes.

public void
addPropertyEditorRegistrar(PropertyEditorRegistrar
the PropertyEditorRegistrar to register
registrar
)

Add a PropertyEditorRegistrar to be applied to all bean creation processes.

public void
copyConfigurationFrom(ConfigurableBeanFactory
the other BeanFactory to copy from
otherFactory
)

Copy all relevant configuration from the given other factory.

public void
copyRegisteredEditorsTo(PropertyEditorRegistry
the PropertyEditorRegistry to initialize
registry
)

Initialize the given PropertyEditorRegistry with the custom editors that have been registered with this BeanFactory.

public void
destroyBean(String
the name of the bean definition
beanName
,
Object
the bean instance to destroy
beanInstance
)

Destroy the given bean instance (usually a prototype instance obtained from this factory) according to its bean definition.

public void
destroyScopedBean(String
the name of the scoped bean
beanName
)

Destroy the specified scoped bean in the current target scope, if any.

public void
destroySingletons()

Destroy all singleton beans in this factory, including inner beans that have been registered as disposable.

public ApplicationStartup
getApplicationStartup()

Return the ApplicationStartup for this bean factory.

public ClassLoader
getBeanClassLoader()

Return this factory's class loader for loading bean classes (only null if even the system ClassLoader isn't accessible).

public BeanExpressionResolver
getBeanExpressionResolver()

Return the resolution strategy for expressions in bean definition values.

public int
getBeanPostProcessorCount()

Return the current number of registered BeanPostProcessors, if any.

public ConversionService
getConversionService()

Return the associated ConversionService, if any.

public String[]

Returns:

the array of names of beans which the bean depends on, or an empty array if none
getDependenciesForBean
(String
the name of the bean
beanName
)

Return the names of all beans that the specified bean depends on, if any.

public String[]

Returns:

the array of dependent bean names, or an empty array if none
getDependentBeans
(String
the name of the bean
beanName
)

Return the names of all beans which depend on the specified bean, if any.

public BeanDefinition

Returns:

a (potentially merged) BeanDefinition for the given bean
getMergedBeanDefinition
(String
the name of the bean to retrieve the merged definition for
beanName
)

Return a merged BeanDefinition for the given bean name, merging a child bean definition with its parent if necessary.

public Scope

Returns:

the registered Scope implementation, or null if none
getRegisteredScope
(String
the name of the scope
scopeName
)

Return the Scope implementation for the given scope name, if any.

public String[]

Returns:

the array of scope names, or an empty array if none
getRegisteredScopeNames
()

Return the names of all currently registered scopes.

public ClassLoader
getTempClassLoader()

Return the temporary ClassLoader to use for type matching purposes, if any.

public TypeConverter
getTypeConverter()

Obtain a type converter as used by this BeanFactory.

public boolean
hasEmbeddedValueResolver()

Determine whether an embedded value resolver has been registered with this bean factory, to be applied through resolveEmbeddedValue(String).

public boolean
isCacheBeanMetadata()

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

public boolean

Returns:

whether the bean is currently in creation
isCurrentlyInCreation
(String
the name of the bean
beanName
)

Determine whether the specified bean is currently in creation.

public boolean

Returns:

whether the bean is a FactoryBean (false means the bean exists but is not a FactoryBean)
isFactoryBean
(String
the name of the bean to check
name
)

Determine whether the bean with the given name is a FactoryBean.

public void
registerAlias(String
the canonical name of the target bean
beanName
,
String
the alias to be registered for the bean
alias
)

Given a bean name, create an alias.

public void
registerCustomEditor(Class<?>
type of the property
requiredType
,
Class<? extends PropertyEditor>
the PropertyEditor class to register
propertyEditorClass
)

Register the given custom property editor for all properties of the given type.

public void
registerDependentBean(String
the name of the bean
beanName
,
String
the name of the dependent bean
dependentBeanName
)

Register a dependent bean for the given bean, to be destroyed before the given bean is destroyed.

public void
registerScope(String
the scope identifier
scopeName
,
Scope
the backing Scope implementation
scope
)

Register the given scope, backed by the given Scope implementation.

public void
resolveAliases(StringValueResolver
the StringValueResolver to apply
valueResolver
)

Resolve all alias target names and aliases registered in this factory, applying the given StringValueResolver to them.

public String

Returns:

the resolved value (may be the original value as-is)
resolveEmbeddedValue
(String
the value to resolve
value
)

Resolve the given embedded value, e.g. an annotation attribute.

public void
setApplicationStartup(ApplicationStartup
the new application startup
applicationStartup
)

Set the ApplicationStartup for this bean factory.

public void
setBeanClassLoader(ClassLoader
the class loader to use, or null to suggest the default class loader
beanClassLoader
)

Set the class loader to use for loading bean classes.

public void
setBeanExpressionResolver(BeanExpressionResolver resolver)

Specify the resolution strategy for expressions in bean definition values.

public void
setCacheBeanMetadata(boolean cacheBeanMetadata)

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

public void
setConversionService(ConversionService conversionService)

Specify a ConversionService to use for converting property values, as an alternative to JavaBeans PropertyEditors.

public void
setCurrentlyInCreation(String
the name of the bean
beanName
,
boolean
whether the bean is currently in creation
inCreation
)

Explicitly control the current in-creation status of the specified bean.

public void
setParentBeanFactory(BeanFactory
the parent BeanFactory
parentBeanFactory
)

Set the parent of this bean factory.

public void
setTempClassLoader(ClassLoader tempClassLoader)

Specify a temporary ClassLoader to use for type matching purposes.

public void
setTypeConverter(TypeConverter typeConverter)

Set a custom type converter that this BeanFactory should use for converting bean property values, constructor argument values, etc.

This will override the default PropertyEditor mechanism and hence make any custom editors or custom editor registrars irrelevant.

Inherited from org.springframework.beans.factory.config.SingletonBeanRegistry:
containsSingletongetSingletongetSingletonCountgetSingletonMutexgetSingletonNamesregisterSingleton
Inherited from org.springframework.beans.factory.HierarchicalBeanFactory:
containsLocalBeangetParentBeanFactory

Field Detail

SCOPE_PROTOTYPEback to summary
public static final String SCOPE_PROTOTYPE

Scope identifier for the standard prototype scope: prototype.

Custom scopes can be added via registerScope.

See Also
registerScope
SCOPE_SINGLETONback to summary
public static final String SCOPE_SINGLETON

Scope identifier for the standard singleton scope: singleton.

Custom scopes can be added via registerScope.

See Also
registerScope

Method Detail

addBeanPostProcessorback to summary
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor)

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

Note

Post-processors submitted here will be applied in the order of registration; any ordering semantics expressed through implementing the org.springframework.core.Ordered interface will be ignored. Note that autodetected post-processors (e.g. as beans in an ApplicationContext) will always be applied after programmatically registered ones.

Parameters
beanPostProcessor:BeanPostProcessor

the post-processor to register

addEmbeddedValueResolverback to summary
public void addEmbeddedValueResolver(StringValueResolver valueResolver)

Add a String resolver for embedded values such as annotation attributes.

Parameters
valueResolver:StringValueResolver

the String resolver to apply to embedded values

Since
3.0
addPropertyEditorRegistrarback to summary
public 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:PropertyEditorRegistrar

the PropertyEditorRegistrar to register

copyConfigurationFromback to summary
public 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:ConfigurableBeanFactory

the other BeanFactory to copy from

copyRegisteredEditorsToback to summary
public void copyRegisteredEditorsTo(PropertyEditorRegistry registry)

Initialize the given PropertyEditorRegistry with the custom editors that have been registered with this BeanFactory.

Parameters
registry:PropertyEditorRegistry

the PropertyEditorRegistry to initialize

destroyBeanback to summary
public 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:String

the name of the bean definition

beanInstance:Object

the bean instance to destroy

destroyScopedBeanback to summary
public 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:String

the name of the scoped bean

destroySingletonsback to summary
public 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.

getApplicationStartupback to summary
public ApplicationStartup getApplicationStartup()

Return the ApplicationStartup for this bean factory.

Since
5.3
getBeanClassLoaderback to summary
public ClassLoader getBeanClassLoader()

Return this factory's class loader for loading bean classes (only null if even the system ClassLoader isn't accessible).

Annotations
@Nullable
See Also
org.springframework.util.ClassUtils#forName(String, ClassLoader)
getBeanExpressionResolverback to summary
public BeanExpressionResolver getBeanExpressionResolver()

Return the resolution strategy for expressions in bean definition values.

Annotations
@Nullable
Since
3.0
getBeanPostProcessorCountback to summary
public int getBeanPostProcessorCount()

Return the current number of registered BeanPostProcessors, if any.

getConversionServiceback to summary
public ConversionService getConversionService()

Return the associated ConversionService, if any.

Annotations
@Nullable
Since
3.0
getDependenciesForBeanback to summary
public String[] getDependenciesForBean(String beanName)

Return the names of all beans that the specified bean depends on, if any.

Parameters
beanName:String

the name of the bean

Returns:String[]

the array of names of beans which the bean depends on, or an empty array if none

Since
2.5
getDependentBeansback to summary
public String[] getDependentBeans(String beanName)

Return the names of all beans which depend on the specified bean, if any.

Parameters
beanName:String

the name of the bean

Returns:String[]

the array of dependent bean names, or an empty array if none

Since
2.5
getMergedBeanDefinitionback to summary
public BeanDefinition getMergedBeanDefinition(String beanName) throws NoSuchBeanDefinitionException

Return a merged BeanDefinition for the given bean name, merging a child bean definition with its parent if necessary. Considers bean definitions in ancestor factories as well.

Parameters
beanName:String

the name of the bean to retrieve the merged definition for

Returns:BeanDefinition

a (potentially merged) BeanDefinition for the given bean

Exceptions
NoSuchBeanDefinitionException:
if there is no bean definition with the given name
Since
2.5
getRegisteredScopeback to summary
public 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:String

the name of the scope

Returns:Scope

the registered Scope implementation, or null if none

Annotations
@Nullable
See Also
registerScope
getRegisteredScopeNamesback to summary
public 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:String[]

the array of scope names, or an empty array if none

See Also
registerScope
getTempClassLoaderback to summary
public ClassLoader getTempClassLoader()

Return the temporary ClassLoader to use for type matching purposes, if any.

Annotations
@Nullable
Since
2.5
getTypeConverterback to summary
public TypeConverter getTypeConverter()

Obtain a type converter as used by this BeanFactory. This may be a fresh instance for each call, since TypeConverters are usually not thread-safe.

If the default PropertyEditor mechanism is active, the returned TypeConverter will be aware of all custom editors that have been registered.

Since
2.5
hasEmbeddedValueResolverback to summary
public boolean hasEmbeddedValueResolver()

Determine whether an embedded value resolver has been registered with this bean factory, to be applied through resolveEmbeddedValue(String).

Since
4.3
isCacheBeanMetadataback to summary
public boolean isCacheBeanMetadata()

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

isCurrentlyInCreationback to summary
public boolean isCurrentlyInCreation(String beanName)

Determine whether the specified bean is currently in creation.

Parameters
beanName:String

the name of the bean

Returns:boolean

whether the bean is currently in creation

Since
2.5
isFactoryBeanback to summary
public boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException

Determine whether the bean with the given name is a FactoryBean.

Parameters
name:String

the name of the bean to check

Returns:boolean

whether the bean is a FactoryBean (false means the bean exists but is not a FactoryBean)

Exceptions
NoSuchBeanDefinitionException:
if there is no bean with the given name
Since
2.5
registerAliasback to summary
public 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:String

the canonical name of the target bean

alias:String

the alias to be registered for the bean

Exceptions
BeanDefinitionStoreException:
if the alias is already in use
registerCustomEditorback to summary
public void registerCustomEditor(Class<?> requiredType, Class<? extends PropertyEditor> propertyEditorClass)

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 preferable to use addPropertyEditorRegistrar instead of this method, to avoid for the need for synchronization on custom editors.

Parameters
requiredType:Class<?>

type of the property

propertyEditorClass:Class<? extends PropertyEditor>

the PropertyEditor class to register

registerDependentBeanback to summary
public void registerDependentBean(String beanName, String dependentBeanName)

Register a dependent bean for the given bean, to be destroyed before the given bean is destroyed.

Parameters
beanName:String

the name of the bean

dependentBeanName:String

the name of the dependent bean

Since
2.5
registerScopeback to summary
public void registerScope(String scopeName, Scope scope)

Register the given scope, backed by the given Scope implementation.

Parameters
scopeName:String

the scope identifier

scope:Scope

the backing Scope implementation

resolveAliasesback to summary
public void resolveAliases(StringValueResolver valueResolver)

Resolve all alias target names and aliases registered in this factory, applying the given StringValueResolver to them.

The value resolver may for example resolve placeholders in target bean names and even in alias names.

Parameters
valueResolver:StringValueResolver

the StringValueResolver to apply

Since
2.5
resolveEmbeddedValueback to summary
public String resolveEmbeddedValue(String value)

Resolve the given embedded value, e.g. an annotation attribute.

Parameters
value:String

the value to resolve

Returns:String

the resolved value (may be the original value as-is)

Annotations
@Nullable
Since
3.0
setApplicationStartupback to summary
public void setApplicationStartup(ApplicationStartup applicationStartup)

Set the ApplicationStartup for this bean factory.

This allows the application context to record metrics during application startup.

Parameters
applicationStartup:ApplicationStartup

the new application startup

Since
5.3
setBeanClassLoaderback to summary
public 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:ClassLoader

the class loader to use, or null to suggest the default class loader

setBeanExpressionResolverback to summary
public void setBeanExpressionResolver(BeanExpressionResolver resolver)

Specify the resolution strategy for expressions in bean definition values.

There is no expression support active in a BeanFactory by default. An ApplicationContext will typically set a standard expression strategy here, supporting "#{...}" expressions in a Unified EL compatible style.

Since
3.0
setCacheBeanMetadataback to summary
public 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.

setConversionServiceback to summary
public void setConversionService(ConversionService conversionService)

Specify a ConversionService to use for converting property values, as an alternative to JavaBeans PropertyEditors.

Since
3.0
setCurrentlyInCreationback to summary
public void setCurrentlyInCreation(String beanName, boolean inCreation)

Explicitly control the current in-creation status of the specified bean. For container-internal use only.

Parameters
beanName:String

the name of the bean

inCreation:boolean

whether the bean is currently in creation

Since
3.1
setParentBeanFactoryback to summary
public 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:BeanFactory

the parent BeanFactory

Exceptions
IllegalStateException:
if this factory is already associated with a parent BeanFactory
See Also
getParentBeanFactory()
setTempClassLoaderback to summary
public void setTempClassLoader(ClassLoader tempClassLoader)

Specify a temporary ClassLoader to use for type matching purposes. Default is none, simply using the standard bean ClassLoader.

A temporary ClassLoader is usually just specified if load-time weaving is involved, to make sure that actual bean classes are loaded as lazily as possible. The temporary loader is then removed once the BeanFactory completes its bootstrap phase.

Since
2.5
setTypeConverterback to summary
public void setTypeConverter(TypeConverter typeConverter)

Set a custom type converter that this BeanFactory should use for converting bean property values, constructor argument values, etc.

This will override the default PropertyEditor mechanism and hence make any custom editors or custom editor registrars irrelevant.

Since
2.5
See Also
addPropertyEditorRegistrar, registerCustomEditor