我有一些使用这些弹簧注释的代码:
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;
我想使用注释中的注释生成一些文档(甚至只是javadocs),例如考虑以下方法?
@ManagedOperation(description="Does foo to bar")
@ManagedOperationParameters({
@ManagedOperationParameter(name = "bar", description = "The bar you want to foo.")})
public long fooBar( Bar bar) throws Exception {
...
}
我是否可以通过某种方式为此自动生成文档,或者除了它之外还需要复制javadoc中的所有注释字符串吗?
答案 0 :(得分:2)
首先,使用委托给getRegisteredObjectNames()的公共方法创建自定义AnnotationMbeanExporter。将其用作mbeanExporter。
例如:
@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.
}