Class DelegatingFactoryBean
- java.lang.Object
-
- io.microsphere.spring.beans.factory.DelegatingFactoryBean
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.FactoryBean<java.lang.Object>
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
public class DelegatingFactoryBean extends java.lang.Object implements org.springframework.beans.factory.FactoryBean<java.lang.Object>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanNameAware
AFactoryBean
implementation that delegates to an existing object instance, providing lifecycle management and integration with Spring'sApplicationContext
.This class is useful when you want to expose an already instantiated object as a Spring bean, while still benefiting from Spring's lifecycle callbacks (e.g.,
InitializingBean
,DisposableBean
, etc.).Key Features:
- Delegates bean creation via the
getObject()
method. - Supports initialization through
InitializingBean.afterPropertiesSet()
. - Supports destruction callback if the delegate implements
DisposableBean
. - Implements Spring's aware interfaces such as
ApplicationContextAware
andBeanNameAware
, delegating calls to the target object if applicable.
Usage Example:
{@code MyService myService = new MyServiceImpl(); DelegatingFactoryBean factoryBean = new DelegatingFactoryBean(myService); // When used in a Spring configuration:
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
FactoryBean
,InitializingBean
,DisposableBean
,ApplicationContextAware
,BeanNameAware
-
-
Constructor Summary
Constructors Constructor Description DelegatingFactoryBean(java.lang.Object delegate)
DelegatingFactoryBean(java.lang.Object delegate, boolean singleton)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
void
destroy()
java.lang.Object
getObject()
java.lang.Class<?>
getObjectType()
boolean
isSingleton()
void
setApplicationContext(org.springframework.context.ApplicationContext context)
void
setBeanName(java.lang.String name)
-
-
-
Method Detail
-
getObject
public java.lang.Object getObject() throws java.lang.Exception
- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<java.lang.Object>
- Throws:
java.lang.Exception
-
getObjectType
public java.lang.Class<?> getObjectType()
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<java.lang.Object>
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext context) throws org.springframework.beans.BeansException
- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
setBeanName
public void setBeanName(java.lang.String name)
- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<java.lang.Object>
-
destroy
public void destroy() throws java.lang.Exception
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
java.lang.Exception
-
-