关于Linux系统中运行的Spring RMI
当我打包 RMI 应用程序并转移到 Linux 系统并运行它时。
日志显示RMI服务正在服务器127.0.0.1上运行(通过InetAddress.getLocalhost()方法打印)。
Host文件中的配置为“127.0.0.1 localhost.localdomain localhost”,所以我认为 RMI 服务器默认将本地主机作为服务器 IP。
之后,我的RMI客户端尝试使用其真实IP(172.16.7.155)调用RMI服务器方法,这导致了异常“拒绝连接127.0.0.1”。
有两种方法可以解决这个问题。一种是修改Host文件并将localhost反映为真实IP(172.16.7.155),但我无法修改它,因为其他应用程序正在使用localhost域。
另一种方法是重置RMI Server获取IP地址的方法,即改为InetAddress.getLocalhost()
,这个方法有配置吗?
When I packed my RMI applications and moved to Linux system and ran it.
The log shows that RMI services are running on server 127.0.0.1(Which was printed by method of InetAddress.getLocalhost()).
The configuration in Host file is "127.0.0.1 localhost.localdomain localhost", so I think RMI server was defalutly got the Localhost as servering IP.
After that, my RMI client try to invoke the RMI server method with its real IP(172.16.7.155) which caused a exception "Refused to connect 127.0.0.1".
There're two ways to reslove this problem. The one is modify Host file and reflect the localhost to real IP(172.16.7.155), but I can not modify it because other applications are using localhost domain.
Another way is to reset the method of fecthing IP address at RMI Server, i.e. instead the InetAddress.getLocalhost()
, is there any configuration for this method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过使用系统属性“-Djava.rmi.server.hostname=172.16.7.155”(或任何盒子的公共IP)启动java rmi服务器进程来解决此问题。 (详细信息此处)
You can probably fix this by starting your java rmi server process with the system property "-Djava.rmi.server.hostname=172.16.7.155" (or whatever the public ip of the box is). (details here)