Top Description Fields Constructors Methods
org.springframework.beans.factory.support

public abstract Class FactoryBeanRegistrySupport

extends DefaultSingletonBeanRegistry
Class Inheritance
Known Direct Subclasses
org.springframework.beans.factory.support.AbstractBeanFactory
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanCreationException, .BeanCurrentlyInCreationException, .FactoryBean, .FactoryBeanNotInitializedException, org.springframework.core.AttributeAccessor, .ResolvableType, org.springframework.lang.Nullable

Support base class for singleton registries which need to handle org.springframework.beans.factory.FactoryBean instances, integrated with DefaultSingletonBeanRegistry's singleton management.

Serves as base class for AbstractBeanFactory.

Author
Juergen Hoeller
Since
2.5.1

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
factoryBeanObjectCache

Cache of singleton objects created by FactoryBeans: FactoryBean name to object.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
private Object

Returns:

the object obtained from the FactoryBean
doGetObjectFromFactoryBean
(FactoryBean<?>
the FactoryBean instance
factory
,
String
the name of the bean
beanName
)

Obtain an object to expose from the given FactoryBean.

protected Object

Returns:

the object obtained from the FactoryBean, or null if not available
getCachedObjectForFactoryBean
(String
the name of the bean
beanName
)

Obtain an object to expose from the given FactoryBean, if available in cached form.

protected FactoryBean<?>

Returns:

the bean instance as FactoryBean
getFactoryBean
(String
the name of the bean
beanName
,
Object
the corresponding bean instance
beanInstance
)

Get a FactoryBean for the given bean if possible.

pack-priv ResolvableType

Returns:

the nested object type, or NONE if not resolvable
getFactoryBeanGeneric
(ResolvableType
the FactoryBean type
type
)

Determine the FactoryBean object type from the given generic declaration.

protected Object

Returns:

the object obtained from the FactoryBean
getObjectFromFactoryBean
(FactoryBean<?>
the FactoryBean instance
factory
,
String
the name of the bean
beanName
,
boolean
whether the bean is subject to post-processing
shouldPostProcess
)

Obtain an object to expose from the given FactoryBean.

protected Class<?>

Returns:

the FactoryBean's object type, or null if the type cannot be determined yet
getTypeForFactoryBean
(FactoryBean<?>
the FactoryBean instance to check
factoryBean
)

Determine the type for the given FactoryBean.

pack-priv ResolvableType

Returns:

a ResolvableType extracted from the attributes or ResolvableType.NONE
getTypeForFactoryBeanFromAttributes
(AttributeAccessor
the attributes to inspect
attributes
)

Determine the bean type for a FactoryBean by inspecting its attributes for a FactoryBean#OBJECT_TYPE_ATTRIBUTE value.

protected Object

Returns:

the object to expose
postProcessObjectFromFactoryBean
(Object
the object obtained from the FactoryBean.
object
,
String
the name of the bean
beanName
)

Post-process the given object that has been obtained from the FactoryBean.

protected void
removeSingleton(String
the name of the bean
beanName
)

Overrides org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.removeSingleton.

Overridden to clear the FactoryBean object cache as well.
Inherited from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry:
addSingletonaddSingletonFactoryafterSingletonCreationbeforeSingletonCreationcontainsSingletondestroyBeandestroySingletondestroySingletonsgetDependenciesForBeangetDependentBeansgetSingletongetSingletongetSingletongetSingletonCountgetSingletonMutexgetSingletonNameshasDependentBeanisActuallyInCreationisCurrentlyInCreationisDependentisSingletonCurrentlyInCreationonSuppressedExceptionregisterContainedBeanregisterDependentBeanregisterDisposableBeanregisterSingletonsetCurrentlyInCreation

Field Detail

factoryBeanObjectCacheback to summary
private final Map<String, Object> factoryBeanObjectCache

Cache of singleton objects created by FactoryBeans: FactoryBean name to object.

Constructor Detail

FactoryBeanRegistrySupportback to summary
public FactoryBeanRegistrySupport()

Method Detail

clearSingletonCacheback to summary
protected void clearSingletonCache()

Overrides org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.clearSingletonCache.

Overridden to clear the FactoryBean object cache as well.

Annotations
@Override
doGetObjectFromFactoryBeanback to summary
private Object doGetObjectFromFactoryBean(FactoryBean<?> factory, String beanName) throws BeanCreationException

Obtain an object to expose from the given FactoryBean.

Parameters
factory:FactoryBean<?>

the FactoryBean instance

beanName:String

the name of the bean

Returns:Object

the object obtained from the FactoryBean

Exceptions
BeanCreationException:
if FactoryBean object creation failed
See Also
org.springframework.beans.factory.FactoryBean#getObject()
getCachedObjectForFactoryBeanback to summary
protected Object getCachedObjectForFactoryBean(String beanName)

Obtain an object to expose from the given FactoryBean, if available in cached form. Quick check for minimal synchronization.

Parameters
beanName:String

the name of the bean

Returns:Object

the object obtained from the FactoryBean, or null if not available

Annotations
@Nullable
getFactoryBeanback to summary
protected FactoryBean<?> getFactoryBean(String beanName, Object beanInstance) throws BeansException

Get a FactoryBean for the given bean if possible.

Parameters
beanName:String

the name of the bean

beanInstance:Object

the corresponding bean instance

Returns:FactoryBean<?>

the bean instance as FactoryBean

Exceptions
BeansException:
if the given bean cannot be exposed as a FactoryBean
getFactoryBeanGenericback to summary
pack-priv ResolvableType getFactoryBeanGeneric(ResolvableType type)

Determine the FactoryBean object type from the given generic declaration.

Parameters
type:ResolvableType

the FactoryBean type

Returns:ResolvableType

the nested object type, or NONE if not resolvable

getObjectFromFactoryBeanback to summary
protected Object getObjectFromFactoryBean(FactoryBean<?> factory, String beanName, boolean shouldPostProcess)

Obtain an object to expose from the given FactoryBean.

Parameters
factory:FactoryBean<?>

the FactoryBean instance

beanName:String

the name of the bean

shouldPostProcess:boolean

whether the bean is subject to post-processing

Returns:Object

the object obtained from the FactoryBean

Exceptions
BeanCreationException:
if FactoryBean object creation failed
See Also
org.springframework.beans.factory.FactoryBean#getObject()
getTypeForFactoryBeanback to summary
protected Class<?> getTypeForFactoryBean(FactoryBean<?> factoryBean)

Determine the type for the given FactoryBean.

Parameters
factoryBean:FactoryBean<?>

the FactoryBean instance to check

Returns:Class<?>

the FactoryBean's object type, or null if the type cannot be determined yet

Annotations
@Nullable
getTypeForFactoryBeanFromAttributesback to summary
pack-priv ResolvableType getTypeForFactoryBeanFromAttributes(AttributeAccessor attributes)

Determine the bean type for a FactoryBean by inspecting its attributes for a FactoryBean#OBJECT_TYPE_ATTRIBUTE value.

Parameters
attributes:AttributeAccessor

the attributes to inspect

Returns:ResolvableType

a ResolvableType extracted from the attributes or ResolvableType.NONE

Since
5.2
postProcessObjectFromFactoryBeanback to summary
protected Object postProcessObjectFromFactoryBean(Object object, String beanName) throws BeansException

Post-process the given object that has been obtained from the FactoryBean. The resulting object will get exposed for bean references.

The default implementation simply returns the given object as-is. Subclasses may override this, for example, to apply post-processors.

Parameters
object:Object

the object obtained from the FactoryBean.

beanName:String

the name of the bean

Returns:Object

the object to expose

Exceptions
BeansException:
if any post-processing failed
removeSingletonback to summary
protected void removeSingleton(String beanName)

Overrides org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.removeSingleton.

Overridden to clear the FactoryBean object cache as well.

Parameters
beanName:String

Doc from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.removeSingleton.

the name of the bean

Annotations
@Override