关于RMI的几个问题解决

版权声明:本文为博主fbysss原创文章,转载请注明出处 https://blog.csdn.net/fbysss/article/details/46367279

作者:fbysss
QQ:溜酒酒吧酒吧吾散
blog:blog.csdn.net/fbysss
声明:本文由fbysss原创,转载请注明出处

1.多网卡导致的RMI连接问题:

Caused by:  java.rmi.ConnectException : Connection refused to host: xx.xx.xx.xxx; nested exception is:
         java.net.ConnectException : Connection timed out: connect
       at sun.rmi.transport.tcp.TCPEndpoint.newSocket(  TCPEndpoint.java:619 ) ~[na:1.7.0_79]

网上也有很多解决方案,其中一个是修改hosts和network文件的。曾经在一个环境下OK,但另一个环境死活不行。
最有效的,不用改代码的,就是在服务器端,指定server ip.
办法:
服务器程序启动的时候,java命令加一个参数:-Djava.rmi.server.hostname=服务器real ip
2.服务器重启之后,客户端再连接就报错了。
在客户端的配置文件中,添加一行:        <property name="refreshStubOnConnectFailure" value="true"/>即可。
样例如下:

    <bean id="userService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" >  
        <property name= "serviceUrl" value="rmi://${rmi.ip}:${rmi.port}/userService" />  
        <property name= "serviceInterface" value="com.xxx.xxxx.resource.service.XxxxxService" />       
        <property name="refreshStubOnConnectFailure" value="true"/>
    </bean>

3.如果RMI服务有问题,客户端应用启动会报错。服务启动后,只能重启应用服务器
解决:在上面的代码段中,再添加一个属性:  <property name="lookupStubOnStartup" value="false"/>
这样,客户端应用服务的启动,不会受到RMI服务状态的影响。因为设置了重连属性,等解决RMI服务的问题之后,刷新客户端请求即可重连。

猜你喜欢

转载自blog.csdn.net/fbysss/article/details/46367279