tomcat下使用rmi出错了

Technology_What 2010-10-04 09:54:17
在我的项目工程中写了一个rmi服务,并用一个servlet调用它,就是在tomcat启动时,这个rmi服务就启动了
但是在这个tomcat启动时,报错了,不知道是什么原因 希望大家帮忙看看,谢谢了。

错误如下图



RMIRunner 类如下:

package server;

import java.rmi.*;
import java.rmi.registry.*;
import javax.naming.*;
import org.apache.log4j.Logger;

public class RMIRunner implements Runnable {

private static Logger log = Logger.getLogger( RMIRunner.class );
private void rmiStart()
{
try
{
System.out.println("11111111111111111");
System.setProperty("java.rmi.server.hostname", "172.21.15.185");

LocateRegistry.createRegistry(1099);

System.out.println("222222222222222222222");
GetResult gr_server = new GetResultImpl("service");


Context namingContext = new InitialContext();

System.out.println("3333333333333333333333");

// namingContext.rebind("coming_server", gr_server);

namingContext.rebind("rmi://172.21.15.185:1099/coming_server", gr_server);
// namingContext.rebind("rmi://localhost:1099/ss", c);
System.out.println("444444444444444444444444444");
log.info( "rmiStart successful. ");

System.out.println("the server is ready! yes!") ;

}
catch (Exception e)
{
log.error( "During rmiStart ", e);
}
}

public void run()
{
rmiStart();
}

}


将这条语句namingContext.rebind("rmi://172.21.15.185:1099/coming_server", gr_server);
换成namingContext.rebind("coming_server", gr_server); 时,tomcat启动时不会报错,但是用客户端启动时,出现找不到coming_server
错误如下:javax.naming.NameNotFoundException:coming_server


package server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RMIInit extends GenericServlet {

/**
* Constructor of the object.
*/
public RMIInit() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}


public void init() throws ServletException {
RMIRunner rmiRunner = new RMIRunner();
Thread t = new Thread(rmiRunner);
t.start();
// Put your code here
}


public void service(ServletRequest arg0, ServletResponse arg1)
throws ServletException, IOException {
// TODO Auto-generated method stub

}

}


...全文
130 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2010-10-04 09:54
社区公告
暂无公告