gpt4 book ai didi

java - Jmx 客户端抛出 InstanceNotFoundException

转载 作者:搜寻专家 更新时间:2023-10-31 19:39:58 26 4
gpt4 key购买 nike

我有一个 Jmx 客户端,用于测试我编写的 jmx bean。这是客户端的代码:

    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);

MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("com.spmsoftware.processing.ping:type=ProcessingPing");

ProcessingPing mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, ProcessingPing.class, true);
System.out.println("\nResult = " + mbeanProxy.ping(346, 0).getResultCode());

jmxc.close();

ProcessingPing 及其所有依赖项都存在于 IntelliJ 的库中。

我的 jmx bean 是:

    public interface ProcessingPing {

public PingResult ping(Integer environmentId, Integer timeout);
}

    @Service("ProcessingPing")
@ManagedResource(description = "")
public class ProcessingPingImpl implements ProcessingPing {

private static final Integer DEFAULT_TIMEOUT = 5000;

@Autowired
private PingProcessService pingProcessService;

@Override
@ManagedOperation(description = "")
public PingResult ping(Integer environmentId, Integer timeout) {
return pingProcessService.run(environmentId, timeout);
}
}

运行时,客户端在尝试调用 ping 方法时出现异常:

    Caused by: javax.management.InstanceNotFoundException: com.spmsoftware.processing.ping:type=ProcessingPing
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getClassLoaderFor(DefaultMBeanServerInterceptor.java:1444)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getClassLoaderFor(JmxMBeanServer.java:1308)
at com.sun.enterprise.v3.admin.DynamicInterceptor.getClassLoaderFor(DynamicInterceptor.java:907)
at javax.management.remote.rmi.RMIConnectionImpl$4.run(RMIConnectionImpl.java:1346)
at java.security.AccessController.doPrivileged(Native Method)
at javax.management.remote.rmi.RMIConnectionImpl.getClassLoaderFor(RMIConnectionImpl.java:1342)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:795)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.invoke(RMIConnector.java:1017)
Disconnected from the target VM, address: '127.0.0.1:56621', transport: 'socket'
at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:305)
... 2 more

我不明白为什么jmx好像能拿到bean,却拿不到类的实际实例。我猜这是一个类路径问题,但找不到它。另一方面,当使用 JConsole 进行测试时,它工作正常。

谢谢

最佳答案

看起来用于注册 MBean 的对象名称与您在尝试检索托管 bean 时使用的对象名称不同。

尝试检查 JConsole 中的对象名称。

关于java - Jmx 客户端抛出 InstanceNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15358407/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com