问题 1已解决!
我对以下问题感到困惑,我正在为我的学校做一个关于 Java 中的 RMI 的项目,我将一个对象放入 RMIRegistery
public static void bindObjectToRMIRegistry(Object obj,String name) throws AccessException, RemoteException {
System.out.println("<< IN ServerHelper.bindObjectToRMIRegistry() >>");
if(getRMIRegistru() != null) {
System.out.println("Binding to registry: "+getRMIRegistru().toString());
getRMIRegistru().rebind(name, (Remote) obj);
}else {
System.out.println("No registry to bind");
}
}
在日志中我收到以下消息:
Binding to registry: RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:192.168.56.1:9005,objID:[0:0:0, 0]]]]
The port is good 9005, but the IP, it's not the good one and I have no ideea where does he get this IP. I also tried to set the HOST for rmi to my localhost 192.168.1.2 but it keeps using this address 192.168.56.1:9005
配置中是否缺少某些内容?
问题2
Registry registery = LocateRegistry.getRegistry("192.168.1.2",9005);
IHello hi = (IHello) registery.lookup("HI");
我得到:RemoteException 错误:错误解码返回;嵌套异常是: java.lang.ClassNotFoundException:Interfaces.IHello(无安全管理器:禁用 RMI 类加载器)
最佳答案
您很可能有多个网络接口(interface),例如LAN、WLAN、用于处理虚拟机的虚拟等。您可以通过运行 ipconfig
(Windows) 或 ifconfig
(Linux) 进行检查。
绑定(bind)RMI时指定正确的IP。如果你有多个,Java 无法猜测你想要哪一个:
Naming.rebind("//192.168.1.2/rmi", new RMI());
关于java - RMI Java | IP 绑定(bind)问题和安全管理器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52916024/