0

从策略文件:

permission java.net.SocketPermission "localhost:1024-", "listen, resolve";
permission java.net.SocketPermission "localhost:1099", "connect, resolve";
permission java.net.SocketPermission "localhost:1024-", "connect, resolve";
permission java.net.SocketPermission "localhost:1024-", "accept, resolve";

有这个代码:

remoteObjName = "blabla";
final objectInterface engine = new object();
final Remote stub = UnicastRemoteObject.exportObject(engine, 0);
final Registry registry = LocateRegistry.getRegistry();
registry.rebind(remoteObjName, stub);//this line causes the exception.

什么可能导致此异常,在最后一行registry.rebind(remoteObjName, stub);

java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: 
        java.net.ConnectException: Connection refused: connect
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
        at sun.rmi.server.UnicastRef.newCall(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
        at app.ConnectionHandler$QAProbeRemote.startEngine(ConnectionHandler.java:47)
        at app.Main.<init>(Main.java:71)
        at app.Main$1.run(Main.java:49)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
        ... 22 more
4

2 回答 2

2

您尚未启动注册表,因此连接失败。

于 2012-09-19T13:37:40.620 回答
0

您需要启动在 JRE 文件夹中找到的“rmiregistry”注册表。

例如,假设您的 JRE 文件夹位于:C:\Program Files\Java\jre1.8.0_271\bin

您可以转到该文件夹​​并运行 rmiregistry.exe

rmir​​egistry.exe 将在控制台中运行。将其留在背景中。

如果您更喜欢通过 cmd 执行此操作,请执行以下操作:

打开cmd,写:

cd C:\Program Files\Java\jre1.8.0_271\bin

点击“Enter”,然后写:

启动 rmiregistry

并再次按“Enter”。

于 2020-12-12T12:40:06.813 回答