spring-framework / org.springframework.aop.framework.autoproxy.target / AbstractBeanFactoryBasedTargetSourceCreator

AbstractBeanFactoryBasedTargetSourceCreator

abstract class AbstractBeanFactoryBasedTargetSourceCreator : TargetSourceCreator, BeanFactoryAware, DisposableBean

Convenient superclass for org.springframework.aop.framework.autoproxy.TargetSourceCreator implementations that require creating multiple instances of a prototype bean.

Uses an internal BeanFactory to manage the target instances, copying the original bean definition to this internal factory. This is necessary because the original BeanFactory will just contain the proxy instance created through auto-proxying.

Requires running in an org.springframework.beans.factory.support.AbstractBeanFactory.

Author
Rod Johnson

Author
Juergen Hoeller

See Also
org.springframework.aop.target.AbstractBeanFactoryBasedTargetSourceorg.springframework.beans.factory.support.AbstractBeanFactory

Constructors

<init>

AbstractBeanFactoryBasedTargetSourceCreator()

Convenient superclass for org.springframework.aop.framework.autoproxy.TargetSourceCreator implementations that require creating multiple instances of a prototype bean.

Uses an internal BeanFactory to manage the target instances, copying the original bean definition to this internal factory. This is necessary because the original BeanFactory will just contain the proxy instance created through auto-proxying.

Requires running in an org.springframework.beans.factory.support.AbstractBeanFactory.

Functions

destroy

open fun destroy(): Unit

Destroys the internal BeanFactory on shutdown of the TargetSourceCreator.

getTargetSource

fun getTargetSource(beanClass: Class<*>, beanName: String): TargetSource

setBeanFactory

fun setBeanFactory(beanFactory: BeanFactory): Unit

Inheritors

LazyInitTargetSourceCreator

open class LazyInitTargetSourceCreator : AbstractBeanFactoryBasedTargetSourceCreator

TargetSourceCreator that enforces a LazyInitTargetSource for each bean that is defined as "lazy-init". This will lead to a proxy created for each of those beans, allowing to fetch a reference to such a bean without actually initializing the target bean instance.

To be registered as custom TargetSourceCreator for an auto-proxy creator, in combination with custom interceptors for specific beans or for the creation of lazy-init proxies only. For example, as autodetected infrastructure bean in an XML application context definition:

 <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="customTargetSourceCreators"> <list> <bean class="org.springframework.aop.framework.autoproxy.target.LazyInitTargetSourceCreator"/> </list> </property> </bean> <bean id="myLazyInitBean" class="mypackage.MyBeanClass" lazy-init="true"> ... </bean>

QuickTargetSourceCreator

open class QuickTargetSourceCreator : AbstractBeanFactoryBasedTargetSourceCreator

Convenient TargetSourceCreator using bean name prefixes to create one of three well-known TargetSource types:

  • : CommonsPool2TargetSource
  • % ThreadLocalTargetSource
  • ! PrototypeTargetSource