jndiutil.java
来自「Junit in Action的随书原代码」· Java 代码 · 共 45 行
JAVA
45 行
package junitbook.ejb.util;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class JNDIUtil
{
private static InitialContext jndiContext;
private static InitialContext getInitialContext()
{
if (jndiContext == null)
{
try
{
jndiContext = new InitialContext();
}
catch (NamingException e)
{
throw new RuntimeException(
"Failed to create InitialContext ["
+ e.getMessage() + "]");
}
}
return jndiContext;
}
public static Object lookup(String name)
{
Object object = null;
try
{
object = getInitialContext().lookup(name);
}
catch (NamingException e)
{
throw new RuntimeException("JNDI lookup failure for ["
+ name + "]. Reason [" + e.getMessage() + "]");
}
return object;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?