Class AbstractFactoryBean<T>
- Type Parameters:
T- the bean type
- All Implemented Interfaces:
Aware,BeanClassLoaderAware,BeanFactoryAware,DisposableBean,FactoryBean<T>,InitializingBean
createInstance() to return null.
Simple template superclass for FactoryBean implementations that
creates a singleton or a prototype object, depending on a flag.
If the "singleton" flag is true (the default),
this class will create the object that it creates exactly once
on initialization and subsequently return said singleton instance
on all calls to the getObject() method.
Else, this class will create a new instance every time the
getObject() method is invoked. Subclasses are responsible
for implementing the abstract createInstance() template
method to actually create the object(s) to expose.
- Since:
- 9.1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classDeprecated, for removal: This API element is subject to removal in a future version.Reflective InvocationHandler for lazy access to the actual singleton object. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ClassLoaderDeprecated, for removal: This API element is subject to removal in a future version.private BeanFactoryDeprecated, for removal: This API element is subject to removal in a future version.private TDeprecated, for removal: This API element is subject to removal in a future version.private booleanDeprecated, for removal: This API element is subject to removal in a future version.private booleanDeprecated, for removal: This API element is subject to removal in a future version.private TDeprecated, for removal: This API element is subject to removal in a future version.Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated, for removal: This API element is subject to removal in a future version.Eagerly create the singleton instance, if necessary.protected abstract TDeprecated, for removal: This API element is subject to removal in a future version.Template method that subclasses must override to construct the object returned by this factory.voiddestroy()Deprecated, for removal: This API element is subject to removal in a future version.Destroy the singleton instance, if any.protected voiddestroyInstance(T instance) Deprecated, for removal: This API element is subject to removal in a future version.Callback for destroying a singleton instance.protected BeanFactoryDeprecated, for removal: This API element is subject to removal in a future version.Return the BeanFactory that this bean runs in.protected TypeConverterDeprecated, for removal: This API element is subject to removal in a future version.Obtain a bean type converter from the BeanFactory that this bean runs in.private TDeprecated, for removal: This API element is subject to removal in a future version.Determine an 'early singleton' instance, exposed in case of a circular reference.protected Class<?>[]Deprecated, for removal: This API element is subject to removal in a future version.Return an array of interfaces that a singleton object exposed by this FactoryBean is supposed to implement, for use with an 'early singleton proxy' that will be exposed in case of a circular reference.final TDeprecated, for removal: This API element is subject to removal in a future version.Expose the singleton instance or create a new prototype instance.abstract Class<?>Deprecated, for removal: This API element is subject to removal in a future version.This abstract method declaration mirrors the method in the FactoryBean interface, for a consistent offering of abstract template methods.private TDeprecated, for removal: This API element is subject to removal in a future version.Expose the singleton instance (for access through the 'early singleton' proxy).booleanDeprecated, for removal: This API element is subject to removal in a future version.voidsetBeanClassLoader(ClassLoader classLoader) Deprecated, for removal: This API element is subject to removal in a future version.voidsetBeanFactory(BeanFactory beanFactory) Deprecated, for removal: This API element is subject to removal in a future version.voidsetSingleton(boolean singleton) Deprecated, for removal: This API element is subject to removal in a future version.Set if a singleton should be created, or a new object on each request otherwise.
-
Field Details
-
singleton
private boolean singletonDeprecated, for removal: This API element is subject to removal in a future version. -
beanClassLoader
Deprecated, for removal: This API element is subject to removal in a future version. -
beanFactory
Deprecated, for removal: This API element is subject to removal in a future version. -
initialized
private boolean initializedDeprecated, for removal: This API element is subject to removal in a future version. -
singletonInstance
Deprecated, for removal: This API element is subject to removal in a future version. -
earlySingletonInstance
Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Constructor Details
-
AbstractFactoryBean
public AbstractFactoryBean()Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
setSingleton
public void setSingleton(boolean singleton) Deprecated, for removal: This API element is subject to removal in a future version.Set if a singleton should be created, or a new object on each request otherwise. Default istrue(a singleton).- Parameters:
singleton- flag to set
-
isSingleton
public boolean isSingleton()Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
isSingletonin interfaceFactoryBean<T>
-
setBeanClassLoader
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware
-
setBeanFactory
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
setBeanFactoryin interfaceBeanFactoryAware
-
getBeanFactory
Deprecated, for removal: This API element is subject to removal in a future version.Return the BeanFactory that this bean runs in.- Returns:
- bean factory
-
getBeanTypeConverter
Deprecated, for removal: This API element is subject to removal in a future version.Obtain a bean type converter from the BeanFactory that this bean runs in. This is typically a fresh instance for each call, since TypeConverters are usually not thread-safe.Falls back to a SimpleTypeConverter when not running in a BeanFactory.
- Returns:
- type converter
- See Also:
-
afterPropertiesSet
Deprecated, for removal: This API element is subject to removal in a future version.Eagerly create the singleton instance, if necessary.- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception
-
getObject
Deprecated, for removal: This API element is subject to removal in a future version.Expose the singleton instance or create a new prototype instance.- Specified by:
getObjectin interfaceFactoryBean<T>- Throws:
Exception- See Also:
-
getEarlySingletonInstance
Deprecated, for removal: This API element is subject to removal in a future version.Determine an 'early singleton' instance, exposed in case of a circular reference. Not called in a non-circular scenario.- Returns:
- early singleton
- Throws:
Exception- on error
-
getSingletonInstance
Deprecated, for removal: This API element is subject to removal in a future version.Expose the singleton instance (for access through the 'early singleton' proxy).- Returns:
- the singleton instance that this FactoryBean holds
- Throws:
IllegalStateException- if the singleton instance is not initialized
-
destroy
Deprecated, for removal: This API element is subject to removal in a future version.Destroy the singleton instance, if any.- Specified by:
destroyin interfaceDisposableBean- Throws:
Exception- See Also:
-
getObjectType
Deprecated, for removal: This API element is subject to removal in a future version.This abstract method declaration mirrors the method in the FactoryBean interface, for a consistent offering of abstract template methods.- Specified by:
getObjectTypein interfaceFactoryBean<T>- See Also:
-
createInstance
Deprecated, for removal: This API element is subject to removal in a future version.Template method that subclasses must override to construct the object returned by this factory.Invoked on initialization of this FactoryBean in case of a singleton; else, on each
getObject()call.- Returns:
- the object returned by this factory
- Throws:
Exception- if an exception occurred during object creation- See Also:
-
getEarlySingletonInterfaces
Deprecated, for removal: This API element is subject to removal in a future version.Return an array of interfaces that a singleton object exposed by this FactoryBean is supposed to implement, for use with an 'early singleton proxy' that will be exposed in case of a circular reference.The default implementation returns this FactoryBean's object type, provided that it is an interface, or
nullotherwise. The latter indicates that early singleton access is not supported by this FactoryBean. This will lead to a FactoryBeanNotInitializedException getting thrown.- Returns:
- the interfaces to use for 'early singletons',
or
nullto indicate a FactoryBeanNotInitializedException - See Also:
-
destroyInstance
Deprecated, for removal: This API element is subject to removal in a future version.Callback for destroying a singleton instance. Subclasses may override this to destroy the previously created instance.The default implementation is empty.
- Parameters:
instance- the singleton instance, as returned bycreateInstance()- Throws:
Exception- in case of shutdown errors- See Also:
-