I have resolved this issue by using programmatic approach by passing the desired objectName while registering the bean. In my POJO which is a managed been I have kept the annotations @ManagedResource (without any options) & @ManagedAttribute as it is.
Before registering the managed bean I am creating & setting the instance of MetadataMBeanInfoAssembler(JMXAttributeSource) so that it can identify the annotation used in the associated object.
Or
You can set the AutodetectMode to AUTODETECT_ASSEMBLER. This will automatically identify the JMX related annotations used in you MBean & expose those operations & attributes.
Code:
public void registerSpringWay(JMXDataHolder holder, final ObjectName objectName) {
try{
AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
exporter.setServer(getPlatFormMBeanServer());
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ASSEMBLER);
exporter.setAssembler(new MetadataMBeanInfoAssembler(new AnnotationJmxAttributeSource()));
exporter.setRegistrationBehavior(MBeanExporter.REGISTRATION_IGNORE_EXISTING);
exporter.registerManagedResource(holder,objectName);
}catch(Exception e){
e.printStackTrace();
}
}
MBeanServer server=null;
/**
* @return
*/
private MBeanServer getPlatFormMBeanServer() {
if(null==server){
this.server= ManagementFactory.getPlatformMBeanServer();
}
return server;
}