V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JasonLaw
V2EX  ›  Java

JMXConnectorFactory.connect 出现“ Java .rmi.ConnectException: Connection refused to host: localhost”

  •  
  •   JasonLaw · 2022-08-23 21:41:52 +08:00 · 1047 次点击
    这是一个创建于 821 天前的主题,其中的信息可能已经有所发展或是发生改变。

    JMXConnectorFactory.connect 的时候出现异常,在网上找了很久,完全没有任何思路。🤕有谁知道怎么解决吗?或者提供一下思路,Thanks in advance.

    java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
            java.net.ConnectException: Connection refused (Connection refused)]
            at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369)
            at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
            at *** internal code ***
            at *** internal code ***
    Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
            java.net.ConnectException: Connection refused (Connection refused)]
            at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:136)
            at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:205)
            at javax.naming.InitialContext.lookup(InitialContext.java:417)
            at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1955)
            at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1922)
            at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
            ... 3 more
    Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
            java.net.ConnectException: Connection refused (Connection refused)
            at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:623)
            at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
            at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
            at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
            at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:116)
            at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:132)
            ... 8 more
    Caused by: java.net.ConnectException: Connection refused (Connection refused)
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
            at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
            at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)
            at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)
            at java.net.Socket.connect(Socket.java:606)
            at java.net.Socket.connect(Socket.java:555)
            at java.net.Socket.<init>(Socket.java:451)
            at java.net.Socket.<init>(Socket.java:228)
            at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
            at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
            at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:617)
            ... 13 more
    Create MBeanServerConnection error!
    
    PendingOni
        1
    PendingOni  
       2022-08-24 11:05:52 +08:00
    1-可以试试改 /etc/hosts 里面的 localhost 的那项, 改成公网 IP
    2-或者在 RMI 的服务端启动脚本里面显式的更改 hostname [ -Djava.rmi.server.hostname=$hostname ]
    PendingOni
        2
    PendingOni  
       2022-08-24 11:09:13 +08:00
    JasonLaw
        3
    JasonLaw  
    OP
       2022-08-24 15:13:34 +08:00
    @PendingOni #1 我现在已经解决了,不过我不太确定我是怎么解决的,因为我现在已经重现不了了。我怀疑是 server 根本没有启动起来,因为我在本地试过了,如果 server 没有启动,尝试 connect 就会出现这个异常,启动后,JMXConnectorFactory.connect 能够正常执行。

    诡异的是,昨天的日志根本没有任何异常信息。

    anyway ,现在已经搞定了。
    PendingOni
        4
    PendingOni  
       2022-08-24 15:18:06 +08:00
    @JasonLaw Fine.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   980 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:09 · PVG 05:09 · LAX 13:09 · JFK 16:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.