程序包 infra.aop.target

类 AbstractLazyCreationTargetSource

java.lang.Object
infra.aop.target.AbstractLazyCreationTargetSource
所有已实现的接口:
TargetClassAware, TargetSource

public abstract class AbstractLazyCreationTargetSource extends Object implements TargetSource
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.

从以下版本开始:
3.0
作者:
Rob Harrop, Juergen Hoeller, TODAY 2021/2/1 21:15
另请参阅:
  • 字段详细资料

    • logger

      protected final infra.logging.Logger logger
      Logger available to subclasses.
    • lazyTarget

      private Object lazyTarget
      The lazily initialized target object.
  • 构造器详细资料

    • AbstractLazyCreationTargetSource

      public AbstractLazyCreationTargetSource()
  • 方法详细资料

    • isInitialized

      public boolean isInitialized()
      Return whether the lazy target object of this TargetSource has already been fetched.
    • getTargetClass

      public Class<?> 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.

      指定者:
      getTargetClass 在接口中 TargetClassAware
      指定者:
      getTargetClass 在接口中 TargetSource
      返回:
      the type of targets returned by this TargetSource
      另请参阅:
    • isStatic

      public boolean isStatic()
      从接口复制的说明: TargetSource
      Will all calls to TargetSource.getTarget() return the same object?

      In that case, there will be no need to invoke TargetSource.releaseTarget(Object), and the AOP framework can cache the return value of TargetSource.getTarget().

      The default implementation returns false.

      指定者:
      isStatic 在接口中 TargetSource
      返回:
      true if the target is immutable
      另请参阅:
    • getTarget

      public Object getTarget() throws Exception
      Returns the lazy-initialized target object, creating it on-the-fly if it doesn't exist already.
      指定者:
      getTarget 在接口中 TargetSource
      返回:
      the target object which contains the join-point, or null if there is no actual target instance
      抛出:
      Exception - if the target object can't be resolved
      另请参阅:
    • createObject

      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.
      返回:
      the created object
      抛出:
      Exception