Top Description Fields Constructors Methods
org.springframework.jndi

public abstract Class JndiLocatorSupport

extends JndiAccessor
Class Inheritance
Known Direct Subclasses
org.springframework.jndi.JndiObjectLocator, org.springframework.jndi.support.SimpleJndiBeanFactory, org.springframework.jndi.JndiLocatorDelegate
Imports
javax.naming.NamingException, org.springframework.lang.Nullable, org.springframework.util.Assert

Convenient superclass for classes that can locate any number of JNDI objects. Derives from JndiAccessor to inherit the "jndiTemplate" and "jndiEnvironment" bean properties.

JNDI names may or may not include the "java:comp/env/" prefix expected by Jakarta EE applications when accessing a locally mapped (ENC - Environmental Naming Context) resource. If it doesn't, the "java:comp/env/" prefix will be prepended if the "resourceRef" property is true (the default is false) and no other scheme (e.g. "java:") is given.

Author
Juergen Hoeller
Since
1.1
See Also
setJndiTemplate, setJndiEnvironment, setResourceRef

Field Summary

Modifier and TypeField and Description
public static final String
CONTAINER_PREFIX

JNDI prefix used in a Jakarta EE container.

private boolean
Inherited from org.springframework.jndi.JndiAccessor:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected String

Returns:

the JNDI name to use
convertJndiName
(String
the original JNDI name
jndiName
)

Convert the given JNDI name into the actual JNDI name to use.

public boolean
isResourceRef()

Return whether the lookup occurs in a Jakarta EE container.

protected Object

Returns:

the obtained object
lookup
(String
the JNDI name to look up
jndiName
)

Perform an actual JNDI lookup for the given name via the JndiTemplate.

protected <T> T

Returns:

the obtained object
lookup
(String
the JNDI name to look up
jndiName
,
Class<T>
the required type of the object
requiredType
)

Perform an actual JNDI lookup for the given name via the JndiTemplate.

public void
setResourceRef(boolean resourceRef)

Set whether the lookup occurs in a Jakarta EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it.

Inherited from org.springframework.jndi.JndiAccessor:
getJndiEnvironmentgetJndiTemplatesetJndiEnvironmentsetJndiTemplate

Field Detail

CONTAINER_PREFIXback to summary
public static final String CONTAINER_PREFIX

JNDI prefix used in a Jakarta EE container.

resourceRefback to summary
private boolean resourceRef

Constructor Detail

JndiLocatorSupportback to summary
public JndiLocatorSupport()

Method Detail

convertJndiNameback to summary
protected String convertJndiName(String jndiName)

Convert the given JNDI name into the actual JNDI name to use.

The default implementation applies the "java:comp/env/" prefix if "resourceRef" is "true" and no other scheme (e.g. "java:") is given.

Parameters
jndiName:String

the original JNDI name

Returns:String

the JNDI name to use

See Also
CONTAINER_PREFIX, setResourceRef
isResourceRefback to summary
public boolean isResourceRef()

Return whether the lookup occurs in a Jakarta EE container.

lookupback to summary
protected Object lookup(String jndiName) throws NamingException

Perform an actual JNDI lookup for the given name via the JndiTemplate.

If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".

Parameters
jndiName:String

the JNDI name to look up

Returns:Object

the obtained object

Exceptions
NamingException:
if the JNDI lookup failed
See Also
setResourceRef
lookupback to summary
protected <T> T lookup(String jndiName, Class<T> requiredType) throws NamingException

Perform an actual JNDI lookup for the given name via the JndiTemplate.

If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".

Parameters
jndiName:String

the JNDI name to look up

requiredType:Class<T>

the required type of the object

Returns:T

the obtained object

Exceptions
NamingException:
if the JNDI lookup failed
See Also
setResourceRef
setResourceRefback to summary
public void setResourceRef(boolean resourceRef)

Set whether the lookup occurs in a Jakarta EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it. Default is "false".

Note

Will only get applied if no other scheme (e.g. "java:") is given.