org.springframework.aop.target
Class LazyInitTargetSource

java.lang.Object
  extended by org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
      extended by org.springframework.aop.target.LazyInitTargetSource
All Implemented Interfaces:
Serializable, TargetSource, BeanFactoryAware

public class LazyInitTargetSource
extends AbstractBeanFactoryBasedTargetSource

TargetSource that lazily accesses a singleton from a BeanFactory.

Useful when a proxy reference is needed on initialization but the actual target object should not be initialized until first use. The target bean must me marked as "lazy-init" too, else it would get instantiated by the BeanFactory on startup. For example:

 <bean id="serviceTarget" class="example.MyService" lazy-init="true">
   ...
 </bean>

 <bean id="service" class="org.springframework.aop.framework.ProxyFactoryBean">
   <property name="targetSource">
     <bean class="org.springframework.aop.target.LazyInitTargetSource">
       <property name="targetBeanName" ref="serviceTarget"/>
     </bean>
   </property>
 </bean>
The "serviceTarget" bean will not get initialized until a method on the "service" proxy gets invoked.

NOTE: Consider specifying "targetClass" if you'd like to avoid any kind of access to the target bean (for example, to avoid initialization of a FactoryBean instance). Default is to detect the type automatically, through a getType call on the BeanFactory, which will trigger FactoryBeans.

Subclasses can extend this class and override the postProcessTargetObject(Object) to perform some additional processing with the target object when it is first loaded.

Since:
1.1.4
Author:
Juergen Hoeller, Rob Harrop
See Also:
AbstractBeanFactoryBasedTargetSource.setTargetClass(java.lang.Class), postProcessTargetObject(java.lang.Object), Serialized Form

Field Summary
 
Fields inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
logger
 
Constructor Summary
LazyInitTargetSource()
           
 
Method Summary
 Object getTarget()
          Return a target instance.
protected  void postProcessTargetObject(Object targetObject)
          Sub-classes may override this method to perform additional processing on the target object when it is first loaded.
 
Methods inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
copyFrom, getBeanFactory, getTargetBeanName, getTargetClass, isStatic, releaseTarget, setBeanFactory, setTargetBeanName, setTargetClass, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyInitTargetSource

public LazyInitTargetSource()
Method Detail

getTarget

public Object getTarget()
                 throws BeansException
Description copied from interface: TargetSource
Return a target instance. Invoked immediately before the AOP framework calls the "target" of an AOP method invocation.

Returns:
the target object, whicch contains the joinpoint
Throws:
BeansException

postProcessTargetObject

protected void postProcessTargetObject(Object targetObject)
Sub-classes may override this method to perform additional processing on the target object when it is first loaded.



Copyright (c) 2002-2006 The Spring Framework Project.