JNDI连接出错问题?

来源:百度知道 编辑:UC知道 时间:2024/05/08 07:38:29
initCtx.lookup("java:comp/env");
运行到这一步就出错,这是什么原因啊?

写的一个列子给你参考下,或许会有帮助
Hashtable ht=new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.DNS_URL,"t3://127.0.0.1:7001");
try {
Context ctx = new InitialContext(ht);
ctx.bind("username","allen");
}catch (Exception e) {
e.printStackTrace();
}

Hashtable ht=new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://127.0.0.1:7001");
try {
Context ctx = new InitialContext(ht);
String str=(String) ctx.lookup("username");
System.out.println(str);
}catch (Exception e) {
e.printStackTrace();
}