Spring RMI 服务器和纯 java RMI 客户端
Spring RMI server and pure java RMI client
我有两个节点通过 RMI 连接。在 RMI 服务器端,我使用 Spring inerfaces (http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp)。在 RMI 客户端,我需要在不知道服务器是否启动的情况下启动它。因此,如果我使用 spring,我的客户端不会启动,并且出现连接拒绝异常。
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="RestoreRMIService" />
<property name="serviceInterface" value="br.com.eb.service.iscsi.RestoreService" />
<property name="service" ref="restoreService" />
</bean>
所以我尝试在客户端使用纯 java RMI (http://www.javacoffeebreak.com/articles/javarmi/javarmi.html)。但是我收到 ClassCastException: com.sun.proxy.$Proxy73 cannot be cast to br.com.eb.service.iscsi.RestoreService。我相信是因为我的 RMI 服务器没有存根。
我想在客户端使用纯 java RMI,因为我需要能够重新启动服务器端。
protected void connectRMI() {
if (!rmiConected) {
try {
Registry registry = LocateRegistry.getRegistry(1099);
serviceRestore = (RestoreService) registry.lookup("RestoreRMIService");
// serviceRestore = (RestoreService) Naming.lookup("rmi://127.0.0.1/RestoreRMIService");
rmiConected = true;
} catch (ConnectException ce) {
System.err.println("Error: server not started");
rmiConected = false;
} catch (ConnectIOException cioe) {
System.err.println("Error: Cannot connect to server at 127.0.0.1");
rmiConected = false;
} catch (Exception e) {
e.printStackTrace();
}
}
}
您不需要为了解决 'connection refused' 异常而切换 RMI 实现。
Java RMI 也有 'connection refused' 个异常。
Java RMI 和 Spring RMI 不互操作。
你的问题没有意义。
我有两个节点通过 RMI 连接。在 RMI 服务器端,我使用 Spring inerfaces (http://www.studytrails.com/frameworks/spring/spring-remoting-rmi.jsp)。在 RMI 客户端,我需要在不知道服务器是否启动的情况下启动它。因此,如果我使用 spring,我的客户端不会启动,并且出现连接拒绝异常。
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="RestoreRMIService" />
<property name="serviceInterface" value="br.com.eb.service.iscsi.RestoreService" />
<property name="service" ref="restoreService" />
</bean>
所以我尝试在客户端使用纯 java RMI (http://www.javacoffeebreak.com/articles/javarmi/javarmi.html)。但是我收到 ClassCastException: com.sun.proxy.$Proxy73 cannot be cast to br.com.eb.service.iscsi.RestoreService。我相信是因为我的 RMI 服务器没有存根。
我想在客户端使用纯 java RMI,因为我需要能够重新启动服务器端。
protected void connectRMI() {
if (!rmiConected) {
try {
Registry registry = LocateRegistry.getRegistry(1099);
serviceRestore = (RestoreService) registry.lookup("RestoreRMIService");
// serviceRestore = (RestoreService) Naming.lookup("rmi://127.0.0.1/RestoreRMIService");
rmiConected = true;
} catch (ConnectException ce) {
System.err.println("Error: server not started");
rmiConected = false;
} catch (ConnectIOException cioe) {
System.err.println("Error: Cannot connect to server at 127.0.0.1");
rmiConected = false;
} catch (Exception e) {
e.printStackTrace();
}
}
}
您不需要为了解决 'connection refused' 异常而切换 RMI 实现。
Java RMI 也有 'connection refused' 个异常。
Java RMI 和 Spring RMI 不互操作。
你的问题没有意义。