问一个有关JNDI的问题:Context.PROVIDER_URL的写法

felix1999 2004-03-28 07:59:28
我是用的服务器是j2sdkee1.3.1,下面是程序代码:
import javax.naming.*;
import java.util.Hashtable;

public class JNDIBind{
private final static String JNDI="sams/book";

public static void main(String args[]){
try{
Hashtable env=new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL,"localhost:1099");
Context ic=new InitialContext(env);
ic.bind(JNDI,"Teach yourself J2EE in 21 days!");
System.out.println("Bind"+JNDI);
}catch(NamingException ex){
ex.printStackTrace();
System.exit(1);
}
}
}
以下是错误信息:
javax.naming.ConfigurationException: Invalid URL: localhost:1099. Root exceptio
n is java.net.MalformedURLException: unknown protocol: localhost
at java.net.URL.<init>(URL.java:586)
at java.net.URL.<init>(URL.java:476)
at java.net.URL.<init>(URL.java:425)
at com.sun.jndi.cosnaming.CNCtx.getStringifiedIor(CNCtx.java:401)
at com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContext(CNCtx.java:198)
at com.sun.jndi.cosnaming.CNCtx.<init>(CNCtx.java:69)
at com.sun.jndi.cosnaming.CNCtxFactory.getInitialContext(CNCtxFactory.ja
va:32)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
62)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at JNDIBind.main(JNDIBind.java:13)
问题肯定是在于Context.INITIAL_CONTEXT_FACTORY和Context.PROVIDER_URL的写法,问题是这两个信息在哪个文件中可以找到,我想在不同的服务器肯定是不同的。
...全文
696 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zengguowen1984 2004-04-10
  • 打赏
  • 举报
回复
楼上的这样就可以绑定了吗,然后客户端就可以调用那个JNDI了吗~
felix1999 2004-04-10
  • 打赏
  • 举报
回复
一个不太好的方法是实行“硬编码”,即把你代码中以下两句
Context initCtx = new InitialContext();
initCtx.bind("DataSource", source);
改成(如果使用j2eesdk的话)
Hashtable env=new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY
"com.sun.jndi.cosnaming.CNCtxFactory ");
env.put(Context.PROVIDER_URL,"iiop://127.0.0.1:1050");
Context ic=new InitialContext(env);
initCtx.bind("DataSource", source);
你先试试看行不行(Context.INITIAL_CONTEXT_FACTORY和Context.PROVIDER_URL的参数值看你具体使用的服务器,上面我已经把各个服务器的值都贴上去了)
seaman0916 2004-04-09
  • 打赏
  • 举报
回复
楼主,我现在想绑定一个数据源,如何在Javabean中得到一个Context ?

-------------------------------
Context initCtx = new InitialContext();
initCtx.bind("DataSource", source);
...............

这个在jsp中可以的,但是我写在JavaBean中就不行了,抛出异常
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

请问:我该如何解决?
dreamnear 2004-03-31
  • 打赏
  • 举报
回复
…楼主的分给我吧,我帮你顶了…呵呵:)

8错,谢谢楼主了
felix1999 2004-03-31
  • 打赏
  • 举报
回复
没人回答,我自己解答:
WebSphere:
Context.INITIAL_CONTEXT_FACTORY
"com.ibm.websphere.naming.WsnInitialContextFactory "
Context.PROVIDER_URL
"iiop://localhost:900 "


Weblogic:
Context.INITIAL_CONTEXT_FACTORY
"weblogic.jndi.WLInitialContextFactory "
Context.PROVIDER_URL
"t3://127.0.0.1:7001 "  

J2EE SDK(J2EE RI):
Context.INITIAL_CONTEXT_FACTORY
"com.sun.jndi.cosnaming.CNCtxFactory "
Context.PROVIDER_URL
"iiop://127.0.0.1:1050 "

SilverStream:
Context.INITIAL_CONTEXT_FACTORY
"com.sssw.rt.jndi.AgInitCtxFactory "
Context.PROVIDER_URL
"sssw://localhost:80 "



OC4J
Context.INITIAL_CONTEXT_FACTORY
"com.evermind.server.rmi.RMIInitialContextFactory"
Context.PROVIDER_URL
"ormi://127.0.0.1/"





JBOSS的:
java.naming.factory.initial
"org.jnp.interfaces.NamingContextFactory"
java.naming.provider.url
"localhost:1099"




WAS5:
Context.INITIAL_CONTEXT_FACTORY
"com.ibm.websphere.naming.WsnInitialContextFactory "
Context.PROVIDER_URL
"iiop://localhost:2809 "

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧