spring-framework / org.springframework.aop.target

Package org.springframework.aop.target

Types

AbstractLazyCreationTargetSource

abstract class AbstractLazyCreationTargetSource : TargetSource

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.

CommonsPool2TargetSource

open class CommonsPool2TargetSource : AbstractPoolingTargetSource, PooledObjectFactory<Any>

org.springframework.aop.TargetSource implementation that holds objects in a configurable Apache Commons2 Pool.

By default, an instance of GenericObjectPool is created. Subclasses may change the type of ObjectPool used by overriding the createObjectPool() method.

Provides many configuration properties mirroring those of the Commons Pool GenericObjectPool class; these properties are passed to the GenericObjectPool during construction. If creating a subclass of this class to change the ObjectPool implementation type, pass in the values of configuration properties that are relevant to your chosen implementation.

The testOnBorrow, testOnReturn and testWhileIdle properties are explicitly not mirrored because the implementation of PoolableObjectFactory used by this class does not implement meaningful validation. All exposed Commons Pool properties use the corresponding Commons Pool defaults.

Compatible with Apache Commons Pool 2.4, as of Spring 4.2.

EmptyTargetSource

open class EmptyTargetSource : TargetSource, Serializable

Canonical TargetSource when there is no target (or just the target class known), and behavior is supplied by interfaces and advisors only.

HotSwappableTargetSource

open class HotSwappableTargetSource : TargetSource, Serializable

org.springframework.aop.TargetSource implementation that caches a local target object, but allows the target to be swapped while the application is running.

If configuring an object of this class in a Spring IoC container, use constructor injection.

This TargetSource is serializable if the target is at the time of serialization.

LazyInitTargetSource

open class LazyInitTargetSource : AbstractBeanFactoryBasedTargetSource

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.

PrototypeTargetSource

open class PrototypeTargetSource : AbstractPrototypeBasedTargetSource

org.springframework.aop.TargetSource implementation that creates a new instance of the target bean for each request, destroying each instance on release (after each request).

Obtains bean instances from its containing org.springframework.beans.factory.BeanFactory.

ThreadLocalTargetSource

open class ThreadLocalTargetSource : AbstractPrototypeBasedTargetSource, ThreadLocalTargetSourceStats, DisposableBean

Alternative to an object pool. This org.springframework.aop.TargetSource uses a threading model in which every thread has its own copy of the target. There's no contention for targets. Target object creation is kept to a minimum on the running server.

Application code is written as to a normal pool; callers can't assume they will be dealing with the same instance in invocations in different threads. However, state can be relied on during the operations of a single thread: for example, if one caller makes repeated calls on the AOP proxy.

Cleanup of thread-bound objects is performed on BeanFactory destruction, calling their DisposableBean.destroy() method if available. Be aware that many thread-bound objects can be around until the application actually shuts down.

ThreadLocalTargetSourceStats

interface ThreadLocalTargetSourceStats

Statistics for a ThreadLocal TargetSource.