public abstract class AbstractBeanFactoryBasedTargetSource extends java.lang.Object implements TargetSource, BeanFactoryAware, java.io.Serializable
TargetSource
implementations
that are based on a Spring BeanFactory
,
delegating to Spring-managed bean instances.
Subclasses can create prototype instances or lazily access a
singleton target, for example. See LazyInitTargetSource
and
AbstractPrototypeBasedTargetSource
's subclasses for concrete strategies.
BeanFactory-based TargetSources are serializable. This involves
disconnecting the current target and turning into a SingletonTargetSource
.
BeanFactory.getBean(java.lang.String)
,
LazyInitTargetSource
,
PrototypeTargetSource
,
ThreadLocalTargetSource
,
CommonsPool2TargetSource
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger available to subclasses
|
Constructor and Description |
---|
AbstractBeanFactoryBasedTargetSource() |
Modifier and Type | Method and Description |
---|---|
protected void |
copyFrom(AbstractBeanFactoryBasedTargetSource other)
Copy configuration from the other AbstractBeanFactoryBasedTargetSource object.
|
boolean |
equals(java.lang.Object other) |
BeanFactory |
getBeanFactory()
Return the owning BeanFactory.
|
java.lang.String |
getTargetBeanName()
Return the name of the target bean in the factory.
|
java.lang.Class<?> |
getTargetClass()
Return the type of targets returned by this
TargetSource . |
int |
hashCode() |
boolean |
isStatic()
Will all calls to
TargetSource.getTarget() return the same object? |
void |
releaseTarget(java.lang.Object target)
Release the given target object obtained from the
TargetSource.getTarget() method, if any. |
void |
setBeanFactory(BeanFactory beanFactory)
Set the owning BeanFactory.
|
void |
setTargetBeanName(java.lang.String targetBeanName)
Set the name of the target bean in the factory.
|
void |
setTargetClass(java.lang.Class<?> targetClass)
Specify the target class explicitly, to avoid any kind of access to the
target bean (for example, to avoid initialization of a FactoryBean instance).
|
java.lang.String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getTarget
protected final Log logger
public AbstractBeanFactoryBasedTargetSource()
public void setTargetBeanName(java.lang.String targetBeanName)
The target bean should not be a singleton, else the same instance will
always be obtained from the factory, resulting in the same behavior as
provided by SingletonTargetSource
.
targetBeanName
- name of the target bean in the BeanFactory
that owns this interceptorSingletonTargetSource
public java.lang.String getTargetBeanName()
public void setTargetClass(java.lang.Class<?> targetClass)
Default is to detect the type automatically, through a getType
call on the BeanFactory (or even a full getBean
call as fallback).
public void setBeanFactory(BeanFactory beanFactory)
getBean
method on every invocation.setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
public BeanFactory getBeanFactory()
public java.lang.Class<?> getTargetClass()
TargetSource
TargetSource
.
Can return null
, although certain usages of a TargetSource
might just work with a predetermined target class.
getTargetClass
in interface TargetClassAware
getTargetClass
in interface TargetSource
TargetSource
public boolean isStatic()
TargetSource
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()
.
isStatic
in interface TargetSource
true
if the target is immutableTargetSource.getTarget()
public void releaseTarget(java.lang.Object target) throws java.lang.Exception
TargetSource
TargetSource.getTarget()
method, if any.releaseTarget
in interface TargetSource
target
- object obtained from a call to TargetSource.getTarget()
java.lang.Exception
- if the object can't be releasedprotected void copyFrom(AbstractBeanFactoryBasedTargetSource other)
other
- object to copy configuration frompublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object