WebSphere下用JNDI

自己遇到过的问题,贴出来让和我遇到同样问题的人参考一下

远程客户端测试代码

Properties properties =new   Properties();
properties.setProperty("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
下面代码中红色的部分,需要注意的是要看自己WebSphere服务器的默认端口号2809是否被占用,如果被占用,则双击服务器进行查看,如我的端口就被重新分配为2811,
properties.setProperty("java.naming.provider.url", "iiop://localhost:2811");
InitialContext ctx = new InitialContext(properties);
if(ctx == null){
System.out.println("ctx is null");
}else{
System.out.println("ctx is not null");
}
System.out.println(ctx.getNameInNamespace());
Object bidManager=ctx.lookup
下面代码中红色的部分,建议查看自己发布工程时控制台上的打印输出的地址,不一定是("工程名/包名/远程接口")
("ejb/ActionBazaar3EAR/ActionBazaar3.jar/BidManagerBean#ejb.bean.actionbazaar.ejb.BidManager");
if(bidManager == null){
System.out.println("bidManager is null");
}else{
System.out.println("bidManager is not null");

猜你喜欢

转载自leowzy.iteye.com/blog/1030405