Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » aop » target » [javadoc | source]
org.springframework.aop.target
public class: LazyInitTargetSource [javadoc | source]
java.lang.Object
   org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
      org.springframework.aop.target.LazyInitTargetSource

All Implemented Interfaces:
    TargetSource, BeanFactoryAware, Serializable

Direct Known Subclasses:
    NotificationPublisherAwareLazyTargetSource

org.springframework.aop.TargetSource that lazily accesses a singleton bean from a org.springframework.beans.factory.BeanFactory .

Useful when a proxy reference is needed on initialization but the actual target object should not be initialized until first use. When the target bean is defined in an org.springframework.context.ApplicationContext (or a BeanFactory that is eagerly pre-instantiating singleton beans) it must be marked as "lazy-init" too, else it will be instantiated by said ApplicationContext (or 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"><idref local="serviceTarget"/></property>
</bean>
</property>
</bean>
The "serviceTarget" bean will not get initialized until a method on the "service" proxy gets invoked.

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

Fields inherited from org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource:
logger
Method from org.springframework.aop.target.LazyInitTargetSource Summary:
getTarget,   postProcessTargetObject
Methods from org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource:
copyFrom,   equals,   getBeanFactory,   getTargetBeanName,   getTargetClass,   hashCode,   isStatic,   releaseTarget,   setBeanFactory,   setTargetBeanName,   setTargetClass,   toString,   writeReplace
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.aop.target.LazyInitTargetSource Detail:
 public synchronized Object getTarget() throws BeansException 
 protected  void postProcessTargetObject(Object targetObject) 
    Subclasses may override this method to perform additional processing on the target object when it is first loaded.