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

public abstract Class AbstractLazyCreationTargetSource

extends Object
implements TargetSource
Class Inheritance
All Implemented Interfaces
org.springframework.aop.TargetSource, org.springframework.aop.TargetClassAware
Imports
org.apache.commons.logging.Log, .LogFactory, org.springframework.aop.TargetSource, org.springframework.lang.Nullable

org.springframework.aop.TargetSource implementation that will lazily create a user-managed object.

Creation of the lazy target object is controlled by the user by implementing the createObject() method. This TargetSource will invoke this method the first time the proxy is accessed.

Useful when you need to pass a reference to some dependency to an object but you don't actually want the dependency to be created until it is first used. A typical scenario for this is a connection to a remote resource.

Authors
Rob Harrop, Juergen Hoeller
Since
1.2.4
See Also
isInitialized(), createObject()

Field Summary

Modifier and TypeField and Description
private Object
lazyTarget

The lazily initialized target object.

protected final Log
logger

Logger available to subclasses.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected abstract Object

Returns:

the created object
createObject
()

Subclasses should implement this method to return the lazy initialized object.

public synchronized Object
getTarget()

Implements org.springframework.aop.TargetSource.getTarget.

Returns the lazy-initialized target object, creating it on-the-fly if it doesn't exist already.
public synchronized Class<?>
getTargetClass()

Implements org.springframework.aop.TargetSource.getTargetClass.

This default implementation returns null if the target is null (it is hasn't yet been initialized), or the target class if the target has already been initialized.
public synchronized boolean
isInitialized()

Return whether the lazy target object of this TargetSource has already been fetched.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lazyTargetback to summary
private Object lazyTarget

The lazily initialized target object.

Annotations
@Nullable
loggerback to summary
protected final Log logger

Logger available to subclasses.

Constructor Detail

AbstractLazyCreationTargetSourceback to summary
public AbstractLazyCreationTargetSource()

Method Detail

createObjectback to summary
protected abstract Object createObject() throws Exception

Subclasses should implement this method to return the lazy initialized object. Called the first time the proxy is invoked.

Returns:Object

the created object

Exceptions
Exception:
if creation failed
getTargetback to summary
public synchronized Object getTarget() throws Exception

Implements org.springframework.aop.TargetSource.getTarget.

Returns the lazy-initialized target object, creating it on-the-fly if it doesn't exist already.

Returns:Object

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

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

Annotations
@Override
Exceptions
Exception:

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

if the target object can't be resolved

See Also
createObject()
getTargetClassback to summary
public synchronized Class<?> getTargetClass()

Implements org.springframework.aop.TargetSource.getTargetClass.

This default implementation returns null if the target is null (it is hasn't yet been initialized), or the target class if the target has already been initialized.

Subclasses may wish to override this method in order to provide a meaningful value when the target is still null.

Returns:Class<?>

Doc from org.springframework.aop.TargetSource.getTargetClass.

the type of targets returned by this TargetSource

Annotations
@Override
@Nullable
See Also
isInitialized()
isInitializedback to summary
public synchronized boolean isInitialized()

Return whether the lazy target object of this TargetSource has already been fetched.