org.springframework.beans.factory.BeanFactory
implementations, providing the full capabilities of the
org.springframework.beans.factory.config.ConfigurableBeanFactory SPI.
Does not assume a listable bean factory: can therefore also be used
as base class for bean factory implementations which obtain bean definitions
from some backend resource (where bean definition access is an expensive operation).
This class provides a singleton cache (through its base class
org.,
singleton/prototype determination, org.
handling, aliases, bean definition merging for child bean definitions,
and bean destruction (org.
interface, custom destroy methods). Furthermore, it can manage a bean factory
hierarchy (delegating to the parent in case of an unknown bean), through implementing
the org. interface.
The main template methods to be implemented by subclasses are
getBeanDefinition and createBean, retrieving a bean definition
for a given bean name and creating a bean instance for a given bean definition,
respectively. Default implementations of those operations can be found in
DefaultListableBeanFactory and AbstractAutowireCapableBeanFactory.
getBeanDefinition, createBean, AbstractAutowireCapableBeanFactory#createBean, DefaultListableBeanFactory#getBeanDefinition
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | AbstractBeanFactory.BeanPostProcessorCache
Internal cache of pre-filtered post-processors. |
| private class | AbstractBeanFactory.BeanPostProcessorCacheAwareList
CopyOnWriteArrayList which resets the beanPostProcessorCache field on modification. |
| Modifier and Type | Field and Description |
|---|---|
| private final Set | alreadyCreated
Names of beans that have already been created at least once. |
| private ApplicationStartup | applicationStartup
Application startup metrics. |
| private ClassLoader | beanClassLoader
ClassLoader to resolve bean class names with, if necessary. |
| private BeanExpressionResolver | beanExpressionResolver
Resolution strategy for expressions in bean definition values. |
| private AbstractBeanFactory. | beanPostProcessorCache
Cache of pre-filtered post-processors. |
| private final List | beanPostProcessors
BeanPostProcessors to apply. |
| private boolean | cacheBeanMetadata
Whether to cache bean metadata or rather reobtain it for every access. |
| private ConversionService | conversionService
Spring ConversionService to use instead of PropertyEditors. |
| private final Map | customEditors
Custom PropertyEditors to apply to the beans of this factory. |
| private final List | embeddedValueResolvers
String resolvers to apply e.g. to annotation attribute values. |
| private final Map | mergedBeanDefinitions
Map from bean name to merged RootBeanDefinition. |
| private BeanFactory | parentBeanFactory
Parent bean factory, for bean inheritance support. |
| private final Set | propertyEditorRegistrars
Custom PropertyEditorRegistrars to apply to the beans of this factory. |
| private final ThreadLocal | prototypesCurrentlyInCreation
Names of beans that are currently in creation. |
| private final Map | scopes
Map from scope identifier String to corresponding Scope. |
| private ClassLoader | tempClassLoader
ClassLoader to temporarily resolve bean class names with, if necessary. |
| private TypeConverter | typeConverter
A custom TypeConverter to use, overriding the default PropertyEditor mechanism. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | AbstractBeanFactory(BeanFactory
parent bean factory, or parentBeanFactory)null if noneCreate a new AbstractBeanFactory with the given parent. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv <T> T | |
| public void | addBeanPostProcessor(BeanPostProcessor
the post-processor to register beanPostProcessor)Implements org. |
| public void | addBeanPostProcessors(Collection<? extends BeanPostProcessor> beanPostProcessors)
Add new BeanPostProcessors that will get applied to beans created by this factory. |
| public void | addEmbeddedValueResolver(StringValueResolver
the String resolver to apply to embedded values valueResolver)Implements org. |
| public void | addPropertyEditorRegistrar(PropertyEditorRegistrar
the PropertyEditorRegistrar to register registrar)Implements org. |
| protected void | afterPrototypeCreation(String
the name of the prototype that has been created beanName)Callback after prototype creation. |
| protected void | beforePrototypeCreation(String
the name of the prototype about to be created beanName)Callback before prototype creation. |
| protected void | checkMergedBeanDefinition(RootBeanDefinition
the merged bean definition to check mbd, String the name of the bean beanName, Object[] the arguments for bean creation, if any args)Check the given merged bean definition, potentially throwing validation exceptions. |
| protected void | cleanupAfterBeanCreationFailure(String
the name of the bean beanName)Perform appropriate cleanup of cached metadata after bean creation failed. |
| protected void | clearMergedBeanDefinition(String
the bean name to clear the merged definition for beanName)Remove the merged bean definition for the specified bean, recreating it on next access. |
| public void | clearMetadataCache()
Clear the merged bean definition cache, removing entries for beans which are not considered eligible for full metadata caching yet. |
| public boolean | containsBean(String
the name of the bean to query name)Implements org. |
| protected abstract boolean | Returns: if this bean factory contains a bean definition with the given namethe name of the bean to look for beanName)Check if this bean factory contains a bean definition with the given name. |
| public boolean | containsLocalBean(String
the name of the bean to query name)Implements org. |
| public void | copyConfigurationFrom(ConfigurableBeanFactory
the other BeanFactory to copy from otherFactory)Implements org. |
| public void | copyRegisteredEditorsTo(PropertyEditorRegistry
the PropertyEditorRegistry to initialize registry)Implements org. |
| private void | |
| protected abstract Object | Returns: a new instance of the beanthe name of the bean beanName, RootBeanDefinition the merged bean definition for the bean mbd, Object[] explicit arguments to use for constructor or factory method invocation args)Create a bean instance for the given merged bean definition (and arguments). |
| public void | destroyBean(String
the name of the bean definition beanName, Object the bean instance to destroy beanInstance)Implements org. |
| protected void | destroyBean(String
the name of the bean definition beanName, Object the bean instance to destroy bean, RootBeanDefinition the merged bean definition mbd)Destroy the given bean instance (usually a prototype instance obtained from this factory) according to the given bean definition. |
| public void | destroyScopedBean(String
the name of the scoped bean beanName)Implements org. |
| protected <T> T | Returns: an instance of the beanthe name of the bean to retrieve name, Class<T> the required type of the bean to retrieve requiredType, Object[] arguments to use when creating a bean instance using explicit arguments
(only applied when creating a new instance as opposed to retrieving an existing one) args, boolean whether the instance is obtained for a type check,
not for actual use typeCheckOnly)Return an instance, which may be shared or independent, of the specified bean. |
| private Class | |
| protected Object | Returns: the resolved valuethe value to check value, BeanDefinition the bean definition that the value comes from beanDefinition)Evaluate the given String as contained in a bean definition, potentially resolving it as an expression. |
| public String[] | getAliases(String
the bean name to check for aliases name)Overrides org. Implements org. |
| public ApplicationStartup | getApplicationStartup()
Implements org. ApplicationStartup for this bean factory.
|
| public Object | getBean(String
the name of the bean to retrieve name)Implements org. |
| public <T> T | getBean(String
the name of the bean to retrieve name, Class<T> type the bean must match; can be an interface or superclass requiredType)Implements org. |
| public Object | getBean(String
the name of the bean to retrieve name, Object... arguments to use when creating a bean instance using explicit arguments
(only applied when creating a new instance as opposed to retrieving an existing one) args)Implements org. |
| public <T> T | Returns: an instance of the beanthe name of the bean to retrieve name, Class<T> the required type of the bean to retrieve requiredType, Object... arguments to use when creating a bean instance using explicit arguments
(only applied when creating a new instance as opposed to retrieving an existing one) args)Return an instance, which may be shared or independent, of the specified bean. |
| public ClassLoader | getBeanClassLoader()
Implements org. null if even the system ClassLoader isn't accessible).
|
| protected abstract BeanDefinition | Returns: the BeanDefinition for this prototype name (nevernull)the name of the bean to find a definition for beanName)Return the bean definition for the given bean name. |
| public BeanExpressionResolver | getBeanExpressionResolver()
Implements org. |
| pack-priv AbstractBeanFactory. | getBeanPostProcessorCache()
Return the internal cache of pre-filtered post-processors, freshly (re-)building it if necessary. |
| public int | getBeanPostProcessorCount()
Implements org. |
| public List | getBeanPostProcessors()
Return the list of BeanPostProcessors that will get applied to beans created with this factory. |
| public ConversionService | getConversionService()
Implements org. |
| public Map | getCustomEditors()
Return the map of custom editors, with Classes as keys and PropertyEditor classes as values. |
| protected TypeConverter | Returns: the custom TypeConverter, ornull if none specifiedReturn the custom TypeConverter to use, if any. |
| public BeanDefinition | Returns: a (potentially merged) RootBeanDefinition for the given beanthe name of the bean to retrieve the merged definition for
(may be an alias) name)Implements org. |
| protected RootBeanDefinition | Returns: a (potentially merged) RootBeanDefinition for the given beanthe name of the bean definition beanName, BeanDefinition the original bean definition (Root/ChildBeanDefinition) bd)Return a RootBeanDefinition for the given top-level bean, by merging with the parent if the given bean's definition is a child bean definition. |
| protected RootBeanDefinition | Returns: a (potentially merged) RootBeanDefinition for the given beanthe name of the bean definition beanName, BeanDefinition the original bean definition (Root/ChildBeanDefinition) bd, BeanDefinition the containing bean definition in case of inner bean,
or containingBd)null in case of a top-level beanReturn a RootBeanDefinition for the given bean, by merging with the parent if the given bean's definition is a child bean definition. |
| protected RootBeanDefinition | Returns: a (potentially merged) RootBeanDefinition for the given beanthe name of the bean to retrieve the merged definition for beanName)Return a merged RootBeanDefinition, traversing the parent bean definition if the specified bean corresponds to a child bean definition. |
| protected Object | Returns: the object to expose for the beanthe shared bean instance beanInstance, String the name that may include factory dereference prefix name, String the canonical bean name beanName, RootBeanDefinition the merged bean definition mbd)Get the object for the given bean instance, either the bean instance itself or its created object in case of a FactoryBean. |
| public BeanFactory | getParentBeanFactory()
Implements org. null if there is none.
|
| public Set | |
| public Scope | getRegisteredScope(String
the name of the scope scopeName)Implements org. |
| public String[] | getRegisteredScopeNames()
Implements org. |
| public ClassLoader | getTempClassLoader()
Implements org. |
| public Class | getType(String
the name of the bean to query name)Implements org. |
| public Class | getType(String
the name of the bean to query name, boolean whether a allowFactoryBeanInit)FactoryBean may get initialized
just for the purpose of determining its object typeImplements org. |
| public TypeConverter | getTypeConverter()
Implements org. |
| protected ResolvableType | Returns: the type for the bean if determinable, otherwiseResolvableType.NONEthe name of the bean beanName, RootBeanDefinition the merged bean definition for the bean mbd, boolean if initialization of the FactoryBean is permitted if the type
cannot be determined another way allowInit)Determine the bean type for the given FactoryBean definition, as far as possible. |
| protected boolean | hasBeanCreationStarted()
Check whether this factory's bean creation phase already started, i.e. whether any bean has been marked as created in the meantime. |
| protected boolean | hasDestructionAwareBeanPostProcessors()
Return whether this factory holds a DestructionAwareBeanPostProcessor that will get applied to singleton beans on shutdown. |
| public boolean | hasEmbeddedValueResolver()
Implements org. resolveEmbeddedValue(String).
|
| protected boolean | hasInstantiationAwareBeanPostProcessors()
Return whether this factory holds a InstantiationAwareBeanPostProcessor that will get applied to singleton beans on creation. |
| protected void | initBeanWrapper(BeanWrapper
the BeanWrapper to initialize bw)Initialize the given BeanWrapper with the custom editors registered with this factory. |
| public boolean | |
| protected boolean | Returns: true if the bean's metadata may be cached
at this point alreadythe name of the bean beanName)Determine whether the specified bean is eligible for having its bean definition metadata cached. |
| public boolean | isBeanNameInUse(String
the name to check beanName)Determine whether the given bean name is already in use within this factory, i.e. whether there is a local bean or alias registered under this name or an inner bean created with this name. |
| public boolean | isCacheBeanMetadata()
Implements org. |
| public boolean | isFactoryBean(String
the name of the bean to check name)Implements org. |
| protected boolean | isFactoryBean(String
the name of the bean beanName, RootBeanDefinition the corresponding bean definition mbd)Check whether the given bean is defined as a |
| public boolean | isPrototype(String
the name of the bean to query name)Implements org. |
| protected boolean | isPrototypeCurrentlyInCreation(String
the name of the bean beanName)Return whether the specified prototype bean is currently in creation (within the current thread). |
| public boolean | isSingleton(String
the name of the bean to query name)Implements org. |
| public boolean | isTypeMatch(String
the name of the bean to query name, ResolvableType the type to match against (as a typeToMatch)ResolvableType)Implements org. |
| protected boolean | Returns: true if the bean type matches, false if it
doesn't match or cannot be determined yetthe name of the bean to query name, ResolvableType the type to match against (as a
typeToMatch, boolean allowFactoryBeanInit)ResolvableType)Internal extended variant of |
| public boolean | isTypeMatch(String
the name of the bean to query name, Class<?> the type to match against (as a typeToMatch)Class)Implements org. |
| protected void | markBeanAsCreated(String
the name of the bean beanName)Mark the specified bean as already created (or about to be created). |
| protected String | Returns: the original bean namethe user-specified name name)Determine the original bean name, resolving locally defined aliases to canonical names. |
| protected Class | Returns: the type of the bean, ornull if not predictablethe name of the bean beanName, RootBeanDefinition the merged bean definition to determine the type for mbd, Class<?>... the types to match in case of internal type matching purposes
(also signals that the returned typesToMatch)Class will never be exposed to application code)Predict the eventual bean type (of the processed bean instance) for the specified bean. |
| public void | registerCustomEditor(Class<?>
type of the property requiredType, Class<? extends PropertyEditor> the propertyEditorClass)PropertyEditor class to registerImplements org. |
| protected void | registerCustomEditors(PropertyEditorRegistry
the PropertyEditorRegistry to initialize registry)Initialize the given PropertyEditorRegistry with the custom editors that have been registered with this BeanFactory. |
| protected void | registerDisposableBeanIfNecessary(String
the name of the bean beanName, Object the bean instance bean, RootBeanDefinition the bean definition for the bean mbd)Add the given bean to the list of disposable beans in this factory, registering its DisposableBean interface and/or the given destroy method to be called on factory shutdown (if applicable). |
| public void | registerScope(String
the scope identifier scopeName, Scope the backing Scope implementation scope)Implements org. |
| protected boolean | Returns: true if actually removed, false otherwisethe name of the bean beanName)Remove the singleton instance (if any) for the given bean name, but only if it hasn't been used for other purposes than type checking. |
| protected boolean | requiresDestruction(Object
the bean instance to check bean, RootBeanDefinition the corresponding bean definition mbd)Determine whether the given bean requires destruction on shutdown. |
| private void | |
| protected Class | Returns: the resolved bean class (ornull if none)the merged bean definition to determine the class for mbd, String the name of the bean (for error handling purposes) beanName, Class<?>... the types to match in case of internal type matching purposes
(also signals that the returned typesToMatch)Class will never be exposed to application code)Resolve the bean class for the specified bean definition, resolving a bean class name into a Class reference (if necessary) and storing the resolved Class in the bean definition for further use. |
| public String | resolveEmbeddedValue(String
the value to resolve value)Implements org. |
| public void | setApplicationStartup(ApplicationStartup
the new application startup applicationStartup)Implements org. ApplicationStartup for this bean factory.
|
| public void | setBeanClassLoader(ClassLoader
the class loader to use,
or beanClassLoader)null to suggest the default class loaderImplements org. |
| public void | setBeanExpressionResolver(BeanExpressionResolver resolver)
Implements org. |
| public void | setCacheBeanMetadata(boolean cacheBeanMetadata)
Implements org. |
| public void | setConversionService(ConversionService conversionService)
Implements org. ConversionService to use for converting
property values, as an alternative to JavaBeans PropertyEditors.
|
| public void | setParentBeanFactory(BeanFactory
the parent BeanFactory parentBeanFactory)Implements org. |
| public void | setTempClassLoader(ClassLoader tempClassLoader)
Implements org. |
| public void | setTypeConverter(TypeConverter typeConverter)
Implements org. This will override the default PropertyEditor mechanism and hence make any custom editors or custom editor registrars irrelevant. |
| protected String | Returns: the transformed bean namethe user-specified name name)Return the bean name, stripping out the factory dereference prefix if necessary, and resolving aliases to canonical names. |