Java Spring Framework jmx managed annotation @ManagedAttribute not showing method in MBeanServerConnection/Jconsole/Visual vm/bean list
Asked Answered
K

2

6

Ive Added Spring annotation's to my code but when connecting via visual vm the method "myExample()" isn't showing in the JMX bean list

My code :

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;


@Component
@ManagedResource
public class MyClass {

   @Autowired
   private Example exampleService;

   @ManagedAttribute
   public String myExample() {
      return exampleService.getSomething().toString();
   }
} 

any idea why this is happening ?

Kicksorter answered 22/8, 2013 at 7:16 Comment(0)
R
7

You should use @ManagedOperation instead. @ManagedAttribute is for a getter / setter methods only.

Redound answered 22/8, 2013 at 7:20 Comment(2)
the only difference is that ManagedOperation is for all methods and ManagedAttribute only for getters and setters ?Kicksorter
See the Javadoc. ManagedOperation can be set in conjunction with ManagedOperationParametersRedound
D
0

It sounds weird, but you can fix it by just renaming myExample to getMyExample.

@ManagedAttribute
public String getMyExample() {
    return exampleService.getSomething().toString();
}

It will even show up as "MyExample" in e.g. visualVM.

Dragonnade answered 21/7, 2023 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.