public class

JndiObjectTargetSource

extends JndiObjectLocator
implements TargetSource
java.lang.Object
   ↳ org.springframework.jndi.JndiAccessor
     ↳ org.springframework.jndi.JndiLocatorSupport
       ↳ org.springframework.jndi.JndiObjectLocator
         ↳ org.springframework.jndi.JndiObjectTargetSource

Class Overview

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).

Summary

[Expand]
Inherited Constants
From class org.springframework.jndi.JndiLocatorSupport
[Expand]
Inherited Fields
From class org.springframework.jndi.JndiAccessor
Public Constructors
JndiObjectTargetSource()
Public Methods
void afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
Object getTarget()
Return a target instance.
Class<?> getTargetClass()
Return the type of targets returned by this TargetSource.
boolean isStatic()
Will all calls to getTarget() return the same object?

In that case, there will be no need to invoke releaseTarget(Object), and the AOP framework can cache the return value of getTarget().

void releaseTarget(Object target)
Release the given target object obtained from the getTarget() method.
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.
[Expand]
Inherited Methods
From class org.springframework.jndi.JndiObjectLocator
From class org.springframework.jndi.JndiLocatorSupport
From class org.springframework.jndi.JndiAccessor
From class java.lang.Object
From interface org.springframework.aop.TargetClassAware
From interface org.springframework.aop.TargetSource
From interface org.springframework.beans.factory.InitializingBean

Public Constructors

public JndiObjectTargetSource ()

Public Methods

public void afterPropertiesSet ()

Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

public Object getTarget ()

Return a target instance. Invoked immediately before the AOP framework calls the "target" of an AOP method invocation.

Returns
  • the target object, which contains the joinpoint

public Class<?> getTargetClass ()

Return the type of targets returned by this TargetSource.

Can return null, although certain usages of a TargetSource might just work with a predetermined target class.

Returns

public boolean isStatic ()

Will all calls to getTarget() return the same object?

In that case, there will be no need to invoke releaseTarget(Object), and the AOP framework can cache the return value of getTarget().

Returns
  • true if the target is immutable

public void releaseTarget (Object target)

Release the given target object obtained from the getTarget() method.

Parameters
target object obtained from a call to getTarget()

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.

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.