|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.beans.factory.support.DefaultSingletonBeanRegistry org.springframework.beans.factory.support.AbstractBeanFactory
public abstract class AbstractBeanFactory
Abstract superclass for BeanFactory implementations, implementing the ConfigurableBeanFactory SPI interface. Does not assume a listable bean factory: can therefore also be used as base class for bean factory implementations which fetch bean definitions from a variety of backend resources (where bean definition access is an expensive operation).
This class provides singleton/prototype determination, singleton cache, aliases, FactoryBean handling, bean definition merging for child bean definitions, and bean destruction (DisposableBean interface, custom destroy methods). Furthermore, it can manage a bean factory hierarchy, through implementing the HierarchicalBeanFactory interface (superinterface of ConfigurableBeanFactory).
The main template methods to be implemented by subclasses are
getBeanDefinition
and createBean
, retrieving a
bean definition for a given bean name or creating a bean instance for a
given bean definition. Default implementations for those can be found in
DefaultListableBeanFactory or AbstractAutowireCapableBeanFactory, respectively.
getBeanDefinition(java.lang.String)
,
createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[])
,
HierarchicalBeanFactory
,
DisposableBean
,
RootBeanDefinition
,
ChildBeanDefinition
,
AbstractAutowireCapableBeanFactory.createBean(java.lang.Class, int, boolean)
,
DefaultListableBeanFactory.getBeanDefinition(java.lang.String)
Field Summary |
---|
Fields inherited from class org.springframework.beans.factory.support.DefaultSingletonBeanRegistry |
---|
logger |
Fields inherited from interface org.springframework.beans.factory.config.ConfigurableBeanFactory |
---|
SCOPE_PROTOTYPE, SCOPE_SINGLETON |
Fields inherited from interface org.springframework.beans.factory.BeanFactory |
---|
FACTORY_BEAN_PREFIX |
Constructor Summary | |
---|---|
AbstractBeanFactory()
Create a new AbstractBeanFactory. |
|
AbstractBeanFactory(BeanFactory parentBeanFactory)
Create a new AbstractBeanFactory with the given parent. |
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. |
protected void |
checkMergedBeanDefinition(RootBeanDefinition mergedBeanDefinition,
String beanName,
Object[] args)
Check the given merged bean definition, potentially throwing validation exceptions. |
boolean |
containsBean(String name)
Does this bean factory contain a bean definition with the given name? |
protected abstract boolean |
containsBeanDefinition(String beanName)
Check if this bean factory contains a bean definition with the given name. |
boolean |
containsLocalBean(String name)
Return whether the local bean factory contains a bean of the given name, ignoring beans defined in ancestor contexts. |
void |
copyConfigurationFrom(ConfigurableBeanFactory otherFactory)
Copy all relevant configuration from the given other factory. |
protected abstract Object |
createBean(String beanName,
RootBeanDefinition mergedBeanDefinition,
Object[] args)
Create a bean instance for the given bean definition. |
void |
destroyBean(String beanName,
Object beanInstance)
Destroy the given bean instance (usually a prototype instance obtained from this factory) according to its bean definition. |
protected void |
destroyBean(String beanName,
Object beanInstance,
RootBeanDefinition mergedBeanDefinition)
Destroy the given bean instance (usually a prototype instance obtained from this factory) according to the given bean definition. |
void |
destroyScopedBean(String beanName)
Destroy the specified scoped bean in the current target scope, if any. |
protected Object |
doTypeConversionIfNecessary(TypeConverter converter,
Object value,
Class targetType,
MethodParameter methodParam)
Convert the given value into the specified target type, using the specified BeanWrapper. |
String[] |
getAliases(String name)
Return the aliases for the given bean name, if defined. |
Object |
getBean(String name)
Return an instance, which may be shared or independent, of the given bean name. |
Object |
getBean(String name,
Class requiredType)
Return an instance (possibly shared or independent) of the given bean name. |
Object |
getBean(String name,
Class requiredType,
Object[] args)
Return the bean with the given name, checking the parent bean factory if not found. |
Object |
getBean(String name,
Object[] args)
Return the bean with the given name, checking the parent bean factory if not found. |
ClassLoader |
getBeanClassLoader()
Return this factory's class loader for loading bean classes. |
protected abstract BeanDefinition |
getBeanDefinition(String beanName)
Return the bean definition for the given bean name. |
int |
getBeanPostProcessorCount()
Return the current number of registered BeanPostProcessors, if any. |
List |
getBeanPostProcessors()
Return the list of BeanPostProcessors that will get applied to beans created with this factory. |
Map |
getCustomEditors()
Return the map of custom editors, with Classes as keys and PropertyEditors as values. |
RootBeanDefinition |
getMergedBeanDefinition(String name)
Return a RootBeanDefinition for the given bean name, merging a child bean definition with its parent if necessary. |
protected RootBeanDefinition |
getMergedBeanDefinition(String beanName,
BeanDefinition bd)
Return a RootBeanDefinition for the given bean name, by merging with the parent if the given original bean definition is a child bean definition. |
protected RootBeanDefinition |
getMergedBeanDefinition(String name,
boolean includingAncestors)
Return a RootBeanDefinition, even by traversing parent if the parameter is a child definition. |
protected Object |
getObjectForBeanInstance(Object beanInstance,
String name,
RootBeanDefinition mbd)
Get the object for the given bean instance, either the bean instance itself or its created object in case of a FactoryBean. |
BeanFactory |
getParentBeanFactory()
Return the parent bean factory, or null if there is none. |
Set |
getPropertyEditorRegistrars()
Return the set of PropertyEditorRegistrars. |
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. |
Class |
getType(String name)
Determine the type of the bean with the given name. |
protected Class |
getTypeForFactoryBean(String beanName,
RootBeanDefinition mergedBeanDefinition)
Determine the bean type for the given FactoryBean definition, as far as possible. |
protected Class |
getTypeForFactoryMethod(String beanName,
RootBeanDefinition mergedBeanDefinition)
Determine the bean type for the given bean definition which is based on a factory method. |
protected boolean |
hasDestructionAwareBeanPostProcessors()
Return whether this factory holds a DestructionAwareBeanPostProcessor that will get applied to singleton beans on shutdown. |
protected void |
initBeanWrapper(BeanWrapper bw)
Initialize the given BeanWrapper with the custom editors registered with this factory. |
protected boolean |
isAlias(String beanName)
Determine whether this given bean name is defines as an alias (as opposed to the name of an actual bean definition). |
protected boolean |
isBeanNameUsed(String beanName)
Return whether the given bean name is already used within this factory, that is, whether there is a local bean registered under this name or an inner bean created with this name. |
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. |
boolean |
isFactoryBean(String name)
Determine whether the bean with the given name is a FactoryBean. |
protected boolean |
isPrototypeCurrentlyInCreation(String beanName)
Return whether the specified prototype bean is currently in creation (within the current thread). |
boolean |
isSingleton(String name)
Is this bean a singleton? |
protected String |
originalBeanName(String name)
Return the original bean name, resolving locally defined aliases to canonical names. |
protected Object |
postProcessObjectFromFactoryBean(Object object,
String beanName)
Post-process the given object that has been obtained from the FactoryBean. |
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. |
protected void |
registerCustomEditors(PropertyEditorRegistry registry)
Initialize the given PropertyEditorRegistry with the custom editors registered with this BeanFactory. |
protected void |
registerDisposableBeanIfNecessary(String beanName,
Object bean,
RootBeanDefinition mergedBeanDefinition)
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). |
void |
registerScope(String scopeName,
Scope scope)
Register the given scope, backed by the given Scope implementation. |
protected void |
removeSingleton(String beanName)
Overridden to clear FactoryBean object cache as well. |
protected boolean |
requiresDestruction(Object bean,
RootBeanDefinition mergedBeanDefinition)
|
protected Class |
resolveBeanClass(RootBeanDefinition mbd,
String beanName)
Resolve the bean class for the specified bean definition, resolving a bean class name into a Class references (if necessary). |
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. |
protected String |
transformedBeanName(String name)
Return the bean name, stripping out the factory dereference prefix if necessary, and resolving aliases to canonical names. |
Methods inherited from class org.springframework.beans.factory.support.DefaultSingletonBeanRegistry |
---|
addSingleton, afterSingletonCreation, beforeSingletonCreation, containsSingleton, destroyBean, destroySingleton, destroySingletons, getDependentBeans, getSingleton, getSingleton, getSingletonCount, getSingletonNames, hasDependentBean, isSingletonCurrentlyInCreation, registerDependentBean, registerDisposableBean, registerSingleton |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.springframework.beans.factory.config.ConfigurableBeanFactory |
---|
destroySingletons |
Methods inherited from interface org.springframework.beans.factory.config.SingletonBeanRegistry |
---|
containsSingleton, getSingleton, getSingletonCount, getSingletonNames, registerSingleton |
Constructor Detail |
---|
public AbstractBeanFactory()
public AbstractBeanFactory(BeanFactory parentBeanFactory)
parentBeanFactory
- parent bean factory, or null
if nonegetBean(java.lang.String)
Method Detail |
---|
public Object getBean(String name) throws BeansException
BeanFactory
Callers may retain references to returned objects in the case of Singleton beans.
Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
getBean
in interface BeanFactory
name
- the name of the bean to return
NoSuchBeanDefinitionException
- if there is no bean definition
with the specified name
BeansException
- if the bean could not be obtainedpublic Object getBean(String name, Class requiredType) throws BeansException
BeanFactory
Behaves the same as getBean(String), but provides a measure of type safety by
throwing a Spring BeansException if the bean is not of the required type.
This means that ClassCastException can't be thrown on casting the result correctly,
as can happen with getBean(String)
.
getBean
in interface BeanFactory
name
- the name of the bean to returnrequiredType
- type the bean must match. Can be an interface or superclass
of the actual class, or null
for any match. For example, if the value
is Object.class
, this method will succeed whatever the class of the
returned instance.
null
)
BeanNotOfRequiredTypeException
- if the bean is not of the required type
NoSuchBeanDefinitionException
- if there's no such bean definition
BeansException
- if the bean could not be createdpublic Object getBean(String name, Object[] args) throws BeansException
name
- the name of the bean to retrieveargs
- arguments to use if creating a prototype using explicit arguments to a
static factory method. It is invalid to use a non-null args value in any other case.
BeansException
public Object getBean(String name, Class requiredType, Object[] args) throws BeansException
name
- the name of the bean to retrieverequiredType
- the required type of the bean to retrieveargs
- arguments to use if creating a prototype using explicit arguments to a
static factory method. It is invalid to use a non-null args value in any other case.
BeansException
public boolean containsBean(String name)
BeanFactory
Will ask the parent factory if the bean cannot be found in this factory instance.
containsBean
in interface BeanFactory
name
- the name of the bean to query
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException
BeanFactory
getBean
always return the same object?
Will ask the parent factory if the bean cannot be found in this factory instance.
isSingleton
in interface BeanFactory
name
- the name of the bean to query
NoSuchBeanDefinitionException
- if there is no bean with the given nameBeanFactory.getBean(java.lang.String)
public Class getType(String name) throws NoSuchBeanDefinitionException
BeanFactory
getBean
would return.
For a FactoryBean, returns the type of object that the FactoryBean creates.
getType
in interface BeanFactory
name
- the name of the bean to query
null
if not determinable
NoSuchBeanDefinitionException
- if there is no bean with the given nameBeanFactory.getBean(java.lang.String)
,
FactoryBean.getObjectType()
public String[] getAliases(String name)
BeanFactory
If the given name is an alias, the corresponding original bean name and other aliases (if any) will be returned, with the original bean name being the first element in the array.
Will ask the parent factory if the bean cannot be found in this factory instance.
getAliases
in interface BeanFactory
name
- the bean name to check for aliases
public BeanFactory getParentBeanFactory()
HierarchicalBeanFactory
null
if there is none.
getParentBeanFactory
in interface HierarchicalBeanFactory
public boolean containsLocalBean(String name)
HierarchicalBeanFactory
This is an alternative to containsBean
, ignoring a bean
of the given name from an ancestor bean factory.
containsLocalBean
in interface HierarchicalBeanFactory
name
- the name of the bean to query
BeanFactory.containsBean(java.lang.String)
public void setParentBeanFactory(BeanFactory parentBeanFactory)
ConfigurableBeanFactory
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.
setParentBeanFactory
in interface ConfigurableBeanFactory
parentBeanFactory
- the parent BeanFactoryHierarchicalBeanFactory.getParentBeanFactory()
public void setBeanClassLoader(ClassLoader beanClassLoader)
ConfigurableBeanFactory
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.
setBeanClassLoader
in interface ConfigurableBeanFactory
beanClassLoader
- the class loader to use,
or null
to suggest the default class loaderpublic ClassLoader getBeanClassLoader()
ConfigurableBeanFactory
getBeanClassLoader
in interface ConfigurableBeanFactory
public void setCacheBeanMetadata(boolean cacheBeanMetadata)
ConfigurableBeanFactory
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.
setCacheBeanMetadata
in interface ConfigurableBeanFactory
public boolean isCacheBeanMetadata()
ConfigurableBeanFactory
isCacheBeanMetadata
in interface ConfigurableBeanFactory
public void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar)
ConfigurableBeanFactory
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
.
addPropertyEditorRegistrar
in interface ConfigurableBeanFactory
registrar
- the PropertyEditorRegistrar to registerConfigurableBeanFactory.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor)
public Set getPropertyEditorRegistrars()
public void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor)
ConfigurableBeanFactory
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.
registerCustomEditor
in interface ConfigurableBeanFactory
requiredType
- type of the propertypropertyEditor
- editor to registerConfigurableBeanFactory.addPropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar)
public Map getCustomEditors()
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor)
ConfigurableBeanFactory
addBeanPostProcessor
in interface ConfigurableBeanFactory
beanPostProcessor
- the bean processor to registerpublic int getBeanPostProcessorCount()
ConfigurableBeanFactory
getBeanPostProcessorCount
in interface ConfigurableBeanFactory
public List getBeanPostProcessors()
protected boolean hasDestructionAwareBeanPostProcessors()
addBeanPostProcessor(org.springframework.beans.factory.config.BeanPostProcessor)
,
DestructionAwareBeanPostProcessor
public void registerScope(String scopeName, Scope scope)
ConfigurableBeanFactory
registerScope
in interface ConfigurableBeanFactory
scopeName
- the scope identifierscope
- the backing Scope implementationpublic String[] getRegisteredScopeNames()
ConfigurableBeanFactory
This will only return the names of explicitly registered scopes. Built-in scopes such as "singleton" and "prototype" won't be exposed.
getRegisteredScopeNames
in interface ConfigurableBeanFactory
ConfigurableBeanFactory.registerScope(java.lang.String, org.springframework.beans.factory.config.Scope)
public Scope getRegisteredScope(String scopeName)
ConfigurableBeanFactory
This will only return explicitly registered scopes. Built-in scopes such as "singleton" and "prototype" won't be exposed.
getRegisteredScope
in interface ConfigurableBeanFactory
scopeName
- the name of the scope
null
if noneConfigurableBeanFactory.registerScope(java.lang.String, org.springframework.beans.factory.config.Scope)
public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory)
ConfigurableBeanFactory
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.
copyConfigurationFrom
in interface ConfigurableBeanFactory
otherFactory
- the other BeanFactory to copy frompublic void registerAlias(String beanName, String alias) throws BeanDefinitionStoreException
ConfigurableBeanFactory
Typically invoked during factory configuration, but can also be used for runtime registration of aliases. Therefore, a factory implementation should synchronize alias access.
registerAlias
in interface ConfigurableBeanFactory
beanName
- the canonical name of the beanalias
- the alias to be registered for the bean
BeanDefinitionStoreException
- if the alias is already in useprotected final boolean isPrototypeCurrentlyInCreation(String beanName)
beanName
- the name of the beanpublic boolean isCurrentlyInCreation(String beanName)
ConfigurableBeanFactory
isCurrentlyInCreation
in interface ConfigurableBeanFactory
beanName
- the name of the beanpublic void destroyBean(String beanName, Object beanInstance)
ConfigurableBeanFactory
Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.
destroyBean
in interface ConfigurableBeanFactory
beanName
- the name of the bean definitionbeanInstance
- the bean instance to destroyprotected void destroyBean(String beanName, Object beanInstance, RootBeanDefinition mergedBeanDefinition)
beanName
- the name of the bean definitionbeanInstance
- the bean instance to destroymergedBeanDefinition
- the merged bean definitionpublic void destroyScopedBean(String beanName)
ConfigurableBeanFactory
Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.
destroyScopedBean
in interface ConfigurableBeanFactory
beanName
- the name of the scoped beanprotected String transformedBeanName(String name)
protected String originalBeanName(String name)
protected boolean isAlias(String beanName)
beanName
- the bean name to checkprotected void initBeanWrapper(BeanWrapper bw)
The default implementation delegates to registerCustomEditors
.
Can be overridden in subclasses.
bw
- the BeanWrapper to initializeregisterCustomEditors(org.springframework.beans.PropertyEditorRegistry)
protected void registerCustomEditors(PropertyEditorRegistry registry)
To be called for BeanWrappers that will create and populate bean instances, and for SimpleTypeConverter used for constructor argument and factory method type conversion.
registry
- the PropertyEditorRegistry to initializeprotected Object doTypeConversionIfNecessary(TypeConverter converter, Object value, Class targetType, MethodParameter methodParam) throws TypeMismatchException
converter
- the TypeConverter to work onvalue
- the original valuetargetType
- the target type
TypeMismatchException
- if type conversion failedBeanWrapperImpl.convertIfNecessary(Object, Class)
public RootBeanDefinition getMergedBeanDefinition(String name) throws BeansException
name
- the name of the bean to retrieve the merged definition for
NoSuchBeanDefinitionException
- if there is no bean with the given name
BeansException
- in case of errorsprotected RootBeanDefinition getMergedBeanDefinition(String name, boolean includingAncestors) throws BeansException
name
- the name of the bean to retrieve the merged definition forincludingAncestors
- whether to ask the parent bean factory if not found
in this instance
NoSuchBeanDefinitionException
- if there is no bean with the given name
BeanDefinitionStoreException
- in case of an invalid bean definition
BeansException
protected RootBeanDefinition getMergedBeanDefinition(String beanName, BeanDefinition bd) throws BeanDefinitionStoreException
beanName
- the name of the bean definitionbd
- the original bean definition (Root/ChildBeanDefinition)
BeanDefinitionStoreException
- in case of an invalid bean definitionprotected void checkMergedBeanDefinition(RootBeanDefinition mergedBeanDefinition, String beanName, Object[] args) throws BeansException
mergedBeanDefinition
- the bean definition to checkbeanName
- the name of the beanargs
- the arguments for bean creation, if any
BeansException
- in case of validation failureprotected Class resolveBeanClass(RootBeanDefinition mbd, String beanName) throws CannotLoadBeanClassException
mbd
- the merged bean definition to determine the class forbeanName
- the name of the bean (for error handling purposes)
null
if none)
CannotLoadBeanClassException
- if we failed to load the classprotected Object getObjectForBeanInstance(Object beanInstance, String name, RootBeanDefinition mbd) throws BeansException
beanInstance
- the shared bean instancename
- name that may include factory dereference prefixmbd
- the merged bean definition
BeansException
public boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException
name
- the name of the bean to check
NoSuchBeanDefinitionException
- if there is no bean with the given nameprotected boolean isBeanNameUsed(String beanName)
beanName
- the name to checkprotected boolean requiresDestruction(Object bean, RootBeanDefinition mergedBeanDefinition)
protected void registerDisposableBeanIfNecessary(String beanName, Object bean, RootBeanDefinition mergedBeanDefinition)
Also registers bean as dependent on other beans, according to the "depends-on" configuration in the bean definition.
beanName
- the name of the beanbean
- the bean instancemergedBeanDefinition
- the bean definition for the beanAbstractBeanDefinition.isSingleton()
,
AbstractBeanDefinition.getDependsOn()
,
DefaultSingletonBeanRegistry.registerDisposableBean(java.lang.String, org.springframework.beans.factory.DisposableBean)
,
DefaultSingletonBeanRegistry.registerDependentBean(java.lang.String, java.lang.String)
protected void removeSingleton(String beanName)
removeSingleton
in class DefaultSingletonBeanRegistry
beanName
- the name of the beanprotected abstract boolean containsBeanDefinition(String beanName)
containsBean
when no cached singleton instance is found.
Depending on the nature of the concrete bean factory implementation, this operation might be expensive (for example, because of directory lookups in external registries). However, for listable bean factories, this usually just amounts to a local hash lookup: The operation is therefore part of the public interface there. The same implementation can serve for both this template method and the public interface method in that case.
beanName
- the name of the bean to look for
containsBean(java.lang.String)
,
ListableBeanFactory.containsBeanDefinition(java.lang.String)
protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeansException
Depending on the nature of the concrete bean factory implementation, this operation might be expensive (for example, because of directory lookups in external registries). However, for listable bean factories, this usually just amounts to a local hash lookup: The operation is therefore part of the public interface there. The same implementation can serve for both this template method and the public interface method in that case.
beanName
- name of the bean to find a definition for
NoSuchBeanDefinitionException
- if the bean definition cannot be resolved
BeansException
- in case of errorsRootBeanDefinition
,
ChildBeanDefinition
,
ConfigurableListableBeanFactory.getBeanDefinition(java.lang.String)
protected abstract Object createBean(String beanName, RootBeanDefinition mergedBeanDefinition, Object[] args) throws BeanCreationException
All the other methods in this class invoke this method, although beans may be cached after being instantiated by this method. All bean instantiation within this class is performed by this method.
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the beanargs
- arguments to use if creating a prototype using explicit arguments
to a static factory method. This parameter must be null
except in this case.
BeanCreationException
- if the bean could not be createdprotected Class getTypeForFactoryMethod(String beanName, RootBeanDefinition mergedBeanDefinition)
Default implementation returns null
to indicate that the
type cannot be determined. Subclasses are encouraged to try to determine
the actual return type here, matching their strategy of resolving
factory methods in the createBean
implementation.
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the bean
null
elsecreateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[])
protected Class getTypeForFactoryBean(String beanName, RootBeanDefinition mergedBeanDefinition)
Default implementation creates the FactoryBean via getBean
to call its getObjectType
method. Subclasses are encouraged to optimize
this, typically by just instantiating the FactoryBean but not populating it yet,
trying whether its getObjectType
method already returns a type.
If no type found, a full FactoryBean creation as performed by this implementation
should be used as fallback.
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the bean
null
elseFactoryBean.getObjectType()
,
getBean(String)
protected Object postProcessObjectFromFactoryBean(Object object, String beanName)
The default implementation simply returns the given object as-is. Subclasses may override this, for example, to apply post-processors.
object
- the object obtained from the FactoryBean.beanName
- the name of the bean
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |