Jmx client throws InstanceNotFoundException

I have a Jmx client that I use to test the jmx bean that I wrote. Here is the code for the client:

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 and all its dependencies are present in the library in IntelliJ.

My jmx beans:

  public interface ProcessingPing { public PingResult ping(Integer environmentId, Integer timeout); } 

and

  @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); } } 

When the client starts, I get an exception when I try to call the ping method:

  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 

I don't understand why jmx seems to be able to get a bean, but not an actual instance of the class. I assume this is a class question, but could not find it. As a side, when testing with JConsole it works fine.

thanks

+4
source share
3 answers

It looks like the name of the object used to register the MBean is different from the name of the object that you use when trying to get a managed bean.

Try checking the name of the object in JConsole.

+7
source

It looks like the name of the object in a specific mbean is different from the one you provide in the JMX client code. The name of the object must match what you define in the java class, as in the class below m bean, using spring.

An example is the bottom line written on top of the @ManagedResource class (objectName = "com.spmsoftware.processing.ping:type=ProcessingPing"

Or you can also check jconsole.exe and go to the mbeans tab and check the mbean name in the left pane.

0
source

In my case, I forgot to create a Bean (in this case ProcessingPingImpl).

Annotation Solution: You can use @Component in Bean and @ComponentScan("com.company") in @ Configuration-Object. (see http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch06s02.html )

Or you create a Bean directly in @ Configuration-Object as follows:

 @Bean public ProcessingPing processingPing(){ return new ProcessingPingImpl(); } 

XML solution:

 <context:component-scan base-package="com.company" /> 

(see https://github.com/spring-by-example/spring-by-example/blob/master/enterprise/spring-jmx/src/test/resources/org/springbyexample/jmx/JmxTest-context.xml )

Or without component scanning:

 <bean id="processingPing" class="com.company.ProcessingPingImpl" /> 
0
source

All Articles