The Spring Framework

org.springframework.aop.framework.autoproxy.target
Class LazyInitTargetSourceCreator

java.lang.Object
  extended by org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator
      extended by org.springframework.aop.framework.autoproxy.target.LazyInitTargetSourceCreator
All Implemented Interfaces:
TargetSourceCreator, BeanFactoryAware, DisposableBean

public class LazyInitTargetSourceCreator
extends 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 initialized 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>

Since:
1.2
Author:
Juergen Hoeller
See Also:
BeanDefinition.isLazyInit(), AbstractAutoProxyCreator.setCustomTargetSourceCreators(org.springframework.aop.framework.autoproxy.TargetSourceCreator[]), BeanNameAutoProxyCreator

Field Summary
 
Fields inherited from class org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator
logger
 
Constructor Summary
LazyInitTargetSourceCreator()
           
 
Method Summary
protected  AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class beanClass, String beanName)
          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 isPrototypeBased()
          Return whether this TargetSourceCreator is prototype-based.
 
Methods inherited from class org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator
destroy, getBeanFactory, getTargetSource, setBeanFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyInitTargetSourceCreator

public LazyInitTargetSourceCreator()
Method Detail

isPrototypeBased

protected boolean isPrototypeBased()
Description copied from class: AbstractBeanFactoryBasedTargetSourceCreator
Return whether this TargetSourceCreator is prototype-based. The scope of the target bean definition will be set accordingly.

Default is "true".

Overrides:
isPrototypeBased in class AbstractBeanFactoryBasedTargetSourceCreator
See Also:
BeanDefinition.isSingleton()

createBeanFactoryBasedTargetSource

protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class beanClass,
                                                                                  String beanName)
Description copied from class: AbstractBeanFactoryBasedTargetSourceCreator
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.

Specified by:
createBeanFactoryBasedTargetSource in class AbstractBeanFactoryBasedTargetSourceCreator
Parameters:
beanClass - the class of the bean to create a TargetSource for
beanName - the name of the bean
Returns:
the AbstractPrototypeBasedTargetSource, or null if we don't match this

The Spring Framework

Copyright © 2002-2007 The Spring Framework.