两台linux上架设rmi出现的奇怪问题

LychieFan 2007-06-08

在两台linux下架设rmi经常会出现以下异常,Naming.lookup(url)中url的ip地址明明是server端的ip,可返回的信息却是被本机的ip拒绝,确实很怪异,异常如下:

java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused

解决方法是在server端的代码中添加一行代码:

System.setProperty("java.rmi.server.hostname",server端的ip);//添加这行代码
LocateRegistry.createRegistry(1099);
RemoteImpl service = new RemoteImpl();
Naming.rebind("RmiServer", service);

相关推荐

Iamlonely / 0评论 2013-01-23