我正在尝试连接到MBean服务器。我需要编写JMX客户端应用程序。这是用于客户端应用程序的代码。但我有个例外
检索RMIServer存根失败: javax.naming.ServiceUnavailableException [根异常为java.rmi.ConnectException:连接拒绝宿主: localhost;嵌套异常为:
有人能帮我解决这个问题吗。
import java.io.IOException;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
public class SystemConfigClient {
public static final String HOST = "localhost";
public static final String PORT = "1099";
public static void main(String[] args) throws IOException, MalformedObjectNameException {
JMXServiceURL url =new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + HOST + ":" +PORT+ "/jmxrmi");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
//ObjectName should be same as your MBean name
ObjectName mbeanName = new ObjectName("ifs.demo1.jmx:type=SystemConfig");
//Get MBean proxy instance that will be used to make calls to registered MBean
SystemConfigMBean mbeanProxy =
(SystemConfigMBean) MBeanServerInvocationHandler.newProxyInstance(
mbeanServerConnection, mbeanName, SystemConfigMBean.class, true);
//let's make some calls to mbean through proxy and see the results.
System.out.println("Current SystemConfig::" + mbeanProxy.doConfig());
mbeanProxy.setSchemaName("NewSchema");
mbeanProxy.setThreadCount(5);
System.out.println("New SystemConfig::" + mbeanProxy.doConfig());
//let's terminate the mbean by making thread count as 0
mbeanProxy.setThreadCount(0);
//close the connection
jmxConnector.close();
}
}我使用以下参数运行了这段代码。
Dcom.sun.management.jmxremote.authenticate=false Dcom.sun.management.jmxremote Dcom.sun.management.jmxremote.port=1099 Dcom.sun.management.jmxremote.ssl=false
但我有个例外
线程“主”java.io.IOException中的异常:无法检索RMIServer存根: javax.naming.ServiceUnavailableException根异常是java.rmi.ConnectException:连接拒绝宿主: localhost;嵌套异常是:连接拒绝:连接在javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338) at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248) at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:207) at com.demo1.jmx.SystemConfigClient.main(SystemConfigClient.java:29)引起: javax.naming.ServiceUnavailableException根异常是java.rmi.ConnectException:连接拒绝主机: localhost;嵌套的例外是:拒绝连接:连接在com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101) at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185) at javax.naming.InitialContext.lookup(InitialContext.java:392) at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886) at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector在javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257) ).又有3种原因: java.rmi.ConnectException:连接拒绝宿主: localhost;嵌套的例外是:连接被拒绝:连接在sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184) at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322) at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)在com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97) .8多个原因是: java.net.ConnectException:连接被拒绝:连接在java.net.PlainSocketImpl.socketConnect(原生方法),在java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195),在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182),在java.net.SocksSocketImpl。连接(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at java.net.Socket.connect(Socket.java:478) at java.net.Socket.(Socket.java:375) at java.net.Socket.(Socket.java:189) at java.net.Socket.connect at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)在sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595) . 13更多的Java结果:1
发布于 2013-07-04 18:49:40
您是否注意到您使用的VM参数与"D“,而不是"-D"?还是只是打错了?正确的做法是:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=falsehttps://stackoverflow.com/questions/16330921
复制相似问题