从政策文件中:
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
答案 0 :(得分:2)
您尚未启动注册表,因此连接失败。
答案 1 :(得分:0)
您需要启动在JRE文件夹中找到的“ rmiregistry”注册表。
例如,假设您的JRE文件夹位于:C:\ Program Files \ Java \ jre1.8.0_271 \ bin
您可以转到该文件夹并运行rmiregistry.exe
rmiregistry.exe将在控制台中运行。留在后台。
如果您希望通过cmd进行操作,请遵循以下步骤:
打开cmd,然后输入:
cd C:\ Program Files \ Java \ jre1.8.0_271 \ bin
点击“ Enter”,然后输入:
启动rmiregistry
然后再次点击“ Enter”。