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

public Class LazyInitTargetSource

extends AbstractBeanFactoryBasedTargetSource
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
org.springframework.beans.BeansException, org.springframework.lang.Nullable

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.

Authors
Juergen Hoeller, Rob Harrop
Since
1.1.4
See Also
org.springframework.beans.factory.BeanFactory#getBean, postProcessTargetObject

Field Summary

Modifier and TypeField and Description
private Object
Inherited from org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized Object
getTarget()

Implements org.springframework.aop.TargetSource.getTarget.

Return a target instance.

protected void
postProcessTargetObject(Object
the target object that has just been instantiated (and configured)
targetObject
)

Subclasses may override this method to perform additional processing on the target object when it is first loaded.

Inherited from org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource:
copyFromequalsgetBeanFactorygetTargetBeanNamegetTargetClasshashCodesetBeanFactorysetTargetBeanNamesetTargetClasstoString

Field Detail

targetback to summary
private Object target
Annotations
@Nullable

Constructor Detail

LazyInitTargetSourceback to summary
public LazyInitTargetSource()

Method Detail

getTargetback to summary
public synchronized Object getTarget() throws BeansException

Implements org.springframework.aop.TargetSource.getTarget.

Doc from org.springframework.aop.TargetSource.getTarget.

Return a target instance. Invoked immediately before the AOP framework calls the "target" of an AOP method invocation.

Returns:Object

the target object which contains the joinpoint, or null if there is no actual target instance

Annotations
@Override
postProcessTargetObjectback to summary
protected void postProcessTargetObject(Object targetObject)

Subclasses may override this method to perform additional processing on the target object when it is first loaded.

Parameters
targetObject:Object

the target object that has just been instantiated (and configured)