Reputation: 9913
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 ?
Upvotes: 6
Views: 5288
Reputation: 6067
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.
Upvotes: 0
Reputation: 19020
You should use @ManagedOperation
instead. @ManagedAttribute
is for a getter / setter methods only.
Upvotes: 7