Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a Jmx Client that i use to test a jmx bean I've written. Here's 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 it's dependencies are present in a library in IntelliJ.
My jmx beans are:
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);
When running, the client, i get an exception when trying to invoke 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 do not understand why jmx seems to be able to get the bean, but not the actual instance of the class. I am guessing it's sort of a classpath issue, but couldn't find it. As a side not, when testing with JConsole, it works fine.
Thanks
It looks like the object name used to register the MBean differs from the object name you use when trying to retrieve the managed bean.
Try to check the object name in JConsole.
–
–
–
Looks like the objectname in mbean defined is different from the one you are providing in JMX client code.
The object name should match exactly as what you define in java class like in below class m bean is exposed by using spring.
Example - the below line written on top of class
@ManagedResource(objectName = "com.spmsoftware.processing.ping:type=ProcessingPing"
Or you can also check in jconsole.exe and go to tab mbeans and check the name of mbean on left pane.
In my case I forgot to create the Bean (in these case ProcessingPingImpl).
Annotation solution:
You can use @Component
on the bean and @ComponentScan("com.company")
on the @Configuration-Object.
(see http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch06s02.html)
Or you create the bean directly in the @Configuration-Object like this:
@Bean
public ProcessingPing processingPing(){
return new ProcessingPingImpl();
XML solution:
<context:component-scan base-package="com.company" />
(see in 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-scan:
<bean id="processingPing" class="com.company.ProcessingPingImpl" />
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.