RMI 调用异常

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

最近在做ehcache的分布式(RMI)缓存的时候发现这个异常,折腾了好一会儿

看官方解释:

写道
Essentially, this java call: InetAddress.getLocalHost();always returns the loopback address, which is 127.0.0.1. Why? Because in these recent distros, a system call of $ hostname always returns an address mapped onto the loopback device. Which causes ehcache’s RMI Peer creation logic to always assign the loopback address, which causes the error you are seeing.
All you need to do is crack open the network config and make sure that the hostname of the machine returns a valid network address accessible by other peers on the network.

大概意思是hostname对应的ip地址是要能被远程调用者能访问,一般情况下在hosts里面加上

写道
hostName IP#能被远程调用的IP,比如调用者在局域网,则应该是本机的局域网IP

其实不难理解

如果你返回的rmi对象包含的是127.0.0.1,调用者根据这个地址调用时会调用到本机....而本机没有这个rmi服务,所以出现上述异常.

猜你喜欢

转载自zhushidan100.iteye.com/blog/1925045
Rmi