开发者

How to auto-generate docs for classes annotated spring jmx annotations

I have some 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 just javadocs) using the comments in the annotations, 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 some way I can automatically generate docs for this, or will I have to duplicate all the annotation strings in javadoc in addition to it?


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

For example:

@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();
  }
}

Then for your report, iterate over the object names returned from getExportedObjectNames() and get the relevant metadata for each JMX bean.

For example:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜