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.?
大概意思是hostname对应的ip地址是要能被远程调用者能访问,一般情况下在hosts里面加上
写道hostName IP#能被远程调用的IP,比如调用者在局域网,则应该是本机的局域网IP?
其实不难理解
?
如果你返回的rmi对象包含的是127.0.0.1,调用者根据这个地址调用时会调用到本机....而本机没有这个rmi服务,所以出现上述异常.
?