public class JndiObjectTargetSource extends JndiObjectLocator implements TargetSource
TargetSource that provides
configurable JNDI lookups for getTarget() calls.
Can be used as alternative to JndiObjectFactoryBean, to allow for
relocating a JNDI object lazily or for each operation (see "lookupOnStartup"
and "cache" properties). This is particularly useful during development, as it
allows for hot restarting of the JNDI server (for example, a remote JMS server).
Example:
<bean id="queueConnectionFactoryTarget" class="org.springframework.jndi.JndiObjectTargetSource"> <property name="jndiName" value="JmsQueueConnectionFactory"/> <property name="lookupOnStartup" value="false"/> </bean> <bean id="queueConnectionFactory" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces" value="javax.jms.QueueConnectionFactory"/> <property name="targetSource" ref="queueConnectionFactoryTarget"/> </bean>A
createQueueConnection call on the "queueConnectionFactory" proxy will
cause a lazy JNDI lookup for "JmsQueueConnectionFactory" and a subsequent delegating
call to the retrieved QueueConnectionFactory's createQueueConnection.
Alternatively, use a JndiObjectFactoryBean with a "proxyInterface".
"lookupOnStartup" and "cache" can then be specified on the JndiObjectFactoryBean,
creating a JndiObjectTargetSource underneath (instead of defining separate
ProxyFactoryBean and JndiObjectTargetSource beans).
setLookupOnStartup(boolean),
setCache(boolean),
AdvisedSupport.setTargetSource(org.springframework.aop.TargetSource),
JndiObjectFactoryBean.setProxyInterface(java.lang.Class<?>)| Modifier and Type | Field and Description |
|---|---|
private boolean |
cache |
private java.lang.Object |
cachedObject |
private boolean |
lookupOnStartup |
private java.lang.Class<?> |
targetClass |
CONTAINER_PREFIXlogger| Constructor and Description |
|---|
JndiObjectTargetSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc. |
java.lang.Object |
getTarget()
Return a target instance.
|
java.lang.Class<?> |
getTargetClass()
Return the type of targets returned by this
TargetSource. |
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 |
setCache(boolean cache)
Set whether to cache the JNDI object once it has been located.
|
void |
setLookupOnStartup(boolean lookupOnStartup)
Set whether to look up the JNDI object on startup.
|
getExpectedType, getJndiName, lookup, setExpectedType, setJndiNameconvertJndiName, isResourceRef, lookup, lookup, setResourceRefgetJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplateprivate boolean lookupOnStartup
private boolean cache
@Nullable private java.lang.Object cachedObject
@Nullable private java.lang.Class<?> targetClass
public void setLookupOnStartup(boolean lookupOnStartup)
Can be turned off to allow for late availability of the JNDI object. In this case, the JNDI object will be fetched on first access.
setCache(boolean)public void setCache(boolean cache)
Can be turned off to allow for hot redeployment of JNDI objects. In this case, the JNDI object will be fetched for each invocation.
setLookupOnStartup(boolean)public void afterPropertiesSet()
throws javax.naming.NamingException
InitializingBeanBeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
afterPropertiesSet in interface InitializingBeanafterPropertiesSet in class JndiObjectLocatorjavax.naming.NamingException@Nullable public java.lang.Class<?> getTargetClass()
TargetSourceTargetSource.
Can return null, although certain usages of a TargetSource
might just work with a predetermined target class.
getTargetClass in interface TargetClassAwaregetTargetClass in interface TargetSourceTargetSourcepublic boolean isStatic()
TargetSourceTargetSource.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 TargetSourcetrue if the target is immutableTargetSource.getTarget()@Nullable public java.lang.Object getTarget()
TargetSourcegetTarget in interface TargetSourcenull if there is no actual target instancepublic void releaseTarget(java.lang.Object target)
TargetSourceTargetSource.getTarget() method, if any.releaseTarget in interface TargetSourcetarget - object obtained from a call to TargetSource.getTarget()