spring-framework / org.springframework.jndi / JndiObjectTargetSource

JndiObjectTargetSource

open class JndiObjectTargetSource : JndiObjectLocator, TargetSource

AOP org.springframework.aop.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).

Author
Juergen Hoeller

Since
1.1

See Also
#setLookupOnStartup#setCacheorg.springframework.aop.framework.ProxyFactoryBean#setTargetSourceJndiObjectFactoryBean#setProxyInterface

Constructors

<init>

JndiObjectTargetSource()

AOP org.springframework.aop.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).

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

getTarget

open fun getTarget(): Any

getTargetClass

open fun getTargetClass(): Class<*>

isStatic

open fun isStatic(): Boolean

releaseTarget

open fun releaseTarget(target: Any): Unit

setCache

open fun setCache(cache: Boolean): Unit

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.

setLookupOnStartup

open fun setLookupOnStartup(lookupOnStartup: Boolean): Unit

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.