Class JndiObjectTargetSource
- All Implemented Interfaces:
org.springframework.aop.TargetClassAware
,org.springframework.aop.TargetSource
,org.springframework.beans.factory.InitializingBean
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="jakarta.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).
- Since:
- 1.1
- Author:
- Juergen Hoeller
- See Also:
-
setLookupOnStartup(boolean)
setCache(boolean)
AdvisedSupport.setTargetSource(org.springframework.aop.TargetSource)
JndiObjectFactoryBean.setProxyInterface(java.lang.Class<?>)
-
Field Summary
Fields inherited from class org.springframework.jndi.JndiLocatorSupport
CONTAINER_PREFIX
Fields inherited from class org.springframework.jndi.JndiAccessor
logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Class<?>
boolean
isStatic()
void
releaseTarget
(Object target) 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.Methods inherited from class org.springframework.jndi.JndiObjectLocator
getExpectedType, getJndiName, lookup, setExpectedType, setJndiName
Methods inherited from class org.springframework.jndi.JndiLocatorSupport
convertJndiName, isResourceRef, lookup, lookup, setResourceRef
Methods inherited from class org.springframework.jndi.JndiAccessor
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate
-
Constructor Details
-
JndiObjectTargetSource
public JndiObjectTargetSource()
-
-
Method Details
-
setLookupOnStartup
public void setLookupOnStartup(boolean lookupOnStartup) Set whether to look up the JNDI object on startup. Default is "true".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.
- See Also:
-
setCache
public void setCache(boolean cache) Set whether to cache the JNDI object once it has been located. Default is "true".Can be turned off to allow for hot redeployment of JNDI objects. In this case, the JNDI object will be fetched for each invocation.
- See Also:
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Overrides:
afterPropertiesSet
in classJndiObjectLocator
- Throws:
NamingException
-
getTargetClass
- Specified by:
getTargetClass
in interfaceorg.springframework.aop.TargetClassAware
- Specified by:
getTargetClass
in interfaceorg.springframework.aop.TargetSource
-
isStatic
public boolean isStatic()- Specified by:
isStatic
in interfaceorg.springframework.aop.TargetSource
-
getTarget
- Specified by:
getTarget
in interfaceorg.springframework.aop.TargetSource
-
releaseTarget
- Specified by:
releaseTarget
in interfaceorg.springframework.aop.TargetSource
-