How to automatically generate documents for classes annotated spring jmx annotations

I have code that uses these spring annotations:

org.springframework.jmx.export.annotation.ManagedAttribute;
org.springframework.jmx.export.annotation.ManagedOperation;
org.springframework.jmx.export.annotation.ManagedOperationParameter;
org.springframework.jmx.export.annotation.ManagedOperationParameters;
org.springframework.jmx.export.annotation.ManagedResource;

I want to generate some documentation (even javadocs) with comments in the annotation, for example, consider the following method?

 @ManagedOperation(description="Does foo to bar")
 @ManagedOperationParameters({
 @ManagedOperationParameter(name = "bar", description = "The bar you want to foo.")})    
 public long fooBar( Bar bar) throws Exception {
   ...
 }

Is there a way to automatically generate documents for this, or will I have to duplicate all annotation lines in javadoc in addition to this?

+3
source share
1 answer

First, create a custom AnnotationMbeanExporter with a public method that delegates to getRegisteredObjectNames (). Use this as your mbeanExporter.

For instance:

@Component
// This is a copy of the AnnotationMBeanExporter with a public version of getRegisteredObjectNames()
public class AnnotationMBeanExporter extends MBeanExporter {

  @Autowired
  MBeanServer mbeanServer;

  AnnotationJmxAttributeSource annotationSource = new AnnotationJmxAttributeSource();

  AnnotationMBeanExporter() {
      setServer(mbeanServer);
      setNamingStrategy(new MetadataNamingStrategy(annotationSource));
      setAssembler(new MetadataMBeanInfoAssembler(annotationSource));
      setAutodetectMode(MBeanExporter.AUTODETECT_ALL);
  }

  public ObjectName[] getExportedObjectNames() {
    return getRegisteredObjectNames();
  }
}

, getExportedObjectNames(), JMX bean.

:

    for (ObjectName objectName: mbeanExporter.getExportedObjectNames()) {
      MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
      MBeanOperationInfo[] operations = mbeanInfo.getOperations();
      // etc.
    }
+2

All Articles