public abstract class JndiLocatorSupport extends JndiAccessor
JNDI names may or may not include the "java:comp/env/" prefix expected by Java 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.
JndiAccessor.setJndiTemplate(org.springframework.jndi.JndiTemplate)
,
JndiAccessor.setJndiEnvironment(java.util.Properties)
,
setResourceRef(boolean)
Modifier and Type | Field and Description |
---|---|
static String |
CONTAINER_PREFIX
JNDI prefix used in a Java EE container.
|
logger
Constructor and Description |
---|
JndiLocatorSupport() |
Modifier and Type | Method and Description |
---|---|
protected String |
convertJndiName(String jndiName)
Convert the given JNDI name into the actual JNDI name to use.
|
boolean |
isResourceRef()
Return whether the lookup occurs in a Java EE container.
|
protected Object |
lookup(String jndiName)
Perform an actual JNDI lookup for the given name via the JndiTemplate.
|
protected <T> T |
lookup(String jndiName,
Class<T> requiredType)
Perform an actual JNDI lookup for the given name via the JndiTemplate.
|
void |
setResourceRef(boolean resourceRef)
Set whether the lookup occurs in a Java EE container, i.e.
|
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate
public static final String CONTAINER_PREFIX
public void setResourceRef(boolean resourceRef)
Note: Will only get applied if no other scheme (e.g. "java:") is given.
public boolean isResourceRef()
protected Object lookup(String jndiName) throws NamingException
If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".
jndiName
- the JNDI name to look upNamingException
- if the JNDI lookup failedsetResourceRef(boolean)
protected <T> T lookup(String jndiName, @Nullable Class<T> requiredType) throws NamingException
If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".
jndiName
- the JNDI name to look uprequiredType
- the required type of the objectNamingException
- if the JNDI lookup failedsetResourceRef(boolean)
protected String convertJndiName(String jndiName)
The default implementation applies the "java:comp/env/" prefix if "resourceRef" is "true" and no other scheme (e.g. "java:") is given.
jndiName
- the original JNDI nameCONTAINER_PREFIX
,
setResourceRef(boolean)