Top Description Fields Constructors Methods
org.springframework.jndi

public Class JndiObjectTargetSource

extends JndiObjectLocator
implements TargetSource
Class Inheritance
All Implemented Interfaces
org.springframework.aop.TargetSource, org.springframework.aop.TargetClassAware
Imports
javax.naming.NamingException, org.springframework.aop.TargetSource, org.springframework.lang.Nullable

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

Author
Juergen Hoeller
Since
1.1
See Also
setLookupOnStartup, setCache, org.springframework.aop.framework.ProxyFactoryBean#setTargetSource, JndiObjectFactoryBean#setProxyInterface

Field Summary

Modifier and TypeField and Description
private boolean
private Object
private boolean
private Class<?>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Overrides org.springframework.jndi.JndiObjectLocator.afterPropertiesSet.

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory 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.

public Object
getTarget()

Implements org.springframework.aop.TargetSource.getTarget.

Return a target instance.

public Class<?>
getTargetClass()

Implements org.springframework.aop.TargetSource.getTargetClass.

Return the type of targets returned by this TargetSource.

public boolean
isStatic()

Overrides default org.springframework.aop.TargetSource.isStatic.

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

public void
setCache(boolean cache)

Set whether to cache the JNDI object once it has been located.

public void
setLookupOnStartup(boolean lookupOnStartup)

Set whether to look up the JNDI object on startup.

Inherited from org.springframework.jndi.JndiObjectLocator:
getExpectedTypegetJndiNamelookupsetExpectedTypesetJndiName

Field Detail

cacheback to summary
private boolean cache
cachedObjectback to summary
private Object cachedObject
Annotations
@Nullable
lookupOnStartupback to summary
private boolean lookupOnStartup
targetClassback to summary
private Class<?> targetClass
Annotations
@Nullable

Constructor Detail

JndiObjectTargetSourceback to summary
public JndiObjectTargetSource()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws NamingException

Overrides org.springframework.jndi.JndiObjectLocator.afterPropertiesSet.

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory 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.

Annotations
@Override
getTargetback to summary
public Object getTarget()

Implements org.springframework.aop.TargetSource.getTarget.

Doc from org.springframework.aop.TargetSource.getTarget.

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

Returns:Object

the target object which contains the joinpoint, or null if there is no actual target instance

Annotations
@Override
@Nullable
getTargetClassback to summary
public Class<?> getTargetClass()

Implements org.springframework.aop.TargetSource.getTargetClass.

Doc from org.springframework.aop.TargetSource.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:Class<?>

the type of targets returned by this TargetSource

Annotations
@Override
@Nullable
isStaticback to summary
public boolean isStatic()

Overrides default org.springframework.aop.TargetSource.isStatic.

Doc from org.springframework.aop.TargetSource.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().

The default implementation returns false.

Returns:boolean

true if the target is immutable

Annotations
@Override
setCacheback to summary
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
setLookupOnStartup
setLookupOnStartupback to summary
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