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 ?

Nimrod007
  • 9,825
  • 8
  • 48
  • 71

2 Answers2

7

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

Ori Dar
  • 18,687
  • 5
  • 58
  • 72
  • the only difference is that ManagedOperation is for all methods and ManagedAttribute only for getters and setters ? – Nimrod007 Aug 22 '13 at 07:25
  • 1
    See the Javadoc. ManagedOperation can be set in conjunction with ManagedOperationParameters – Ori Dar Aug 22 '13 at 07:30
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.

Sebastian
  • 5,721
  • 3
  • 43
  • 69