Top Description Fields Constructors Methods
org.springframework.aop.framework.autoproxy.target

public Class LazyInitTargetSourceCreator

extends AbstractBeanFactoryBasedTargetSourceCreator
Class Inheritance
Imports
org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource, .LazyInitTargetSource, org.springframework.beans.factory.config.BeanDefinition, .ConfigurableListableBeanFactory, org.springframework.lang.Nullable

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 an autodetected infrastructure bean in an XML application context definition:

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="beanNames" value="*" /> <!-- apply to all beans -->
  <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>
Authors
Juergen Hoeller, Sam Brannen
Since
1.2
See Also
org.springframework.beans.factory.config.BeanDefinition#isLazyInit, org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#setCustomTargetSourceCreators, org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator

Field Summary

Inherited from org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected AbstractBeanFactoryBasedTargetSource
createBeanFactoryBasedTargetSource(Class<?>
the class of the bean to create a TargetSource for
beanClass
,
String
the name of the bean
beanName
)

Implements abstract org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator.createBeanFactoryBasedTargetSource.

Subclasses must implement this method to return a new AbstractPrototypeBasedTargetSource if they wish to create a custom TargetSource for this bean, or null if they are not interested it in, in which case no special target source will be created.

protected boolean
Inherited from org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator:
buildInternalBeanFactorydestroygetBeanFactorygetInternalBeanFactoryForBeangetTargetSourcesetBeanFactory

Constructor Detail

LazyInitTargetSourceCreatorback to summary
public LazyInitTargetSourceCreator()

Method Detail

createBeanFactoryBasedTargetSourceback to summary
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName)

Implements abstract org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator.createBeanFactoryBasedTargetSource.

Doc from org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator.createBeanFactoryBasedTargetSource.

Subclasses must implement this method to return a new AbstractPrototypeBasedTargetSource if they wish to create a custom TargetSource for this bean, or null if they are not interested it in, in which case no special target source will be created. Subclasses should not call setTargetBeanName or setBeanFactory on the AbstractPrototypeBasedTargetSource: This class' implementation of getTargetSource() will do that.

Parameters
beanClass:Class<?>

the class of the bean to create a TargetSource for

beanName:String

the name of the bean

Returns:AbstractBeanFactoryBasedTargetSource

the AbstractPrototypeBasedTargetSource, or null if we don't match this

Annotations
@Override
@Nullable
isPrototypeBasedback to summary
protected boolean isPrototypeBased()

Overrides org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator.isPrototypeBased.

Doc from org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator.isPrototypeBased.

Return whether this TargetSourceCreator is prototype-based. The scope of the target bean definition will be set accordingly.

Default is "true".

Annotations
@Override