我想在JBoss jmx-console中使我的标准MBean详细. DynamicMBean有getMBeanInfo()来做.方法返回MBeanInfo,其中包含MBean的描述.但是我怎么能为Standard MBean做同样的事情呢?例如.我有以下MBean接口:
public interface MyMBean {
String f();
}
……以下实施:
public class My implements MyMBean {
public String f() {
return "test";
}
}
在这样的例子中应该怎么做才能添加描述?
谢谢
解决方法:
对于StandardMBeans,无法添加描述或其他元信息.
从MBeanInfo的JavaDoc:
The remaining details of the MBeanInfo for a Standard MBean are not specified. This includes the description of the MBeanInfo and of any contained constructors, attributes, operations, and notifications; and the names and descriptions of parameters to constructors and operations.
因此,您至少需要使用DynamicMBeans(或ModelMBean或OpenMBean)来指定此信息. Spring可以帮助你,因为它允许通过注释创建DynamicMBeans,最后使用它比编写自己的StandardMBeans更简单.示例(来自spring文档):
@ManagedResource(objectName="bean:name=testBean4",
description="My Managed Bean")
public class AnnotationTestBean {
private int age;
@ManagedAttribute(description="The Age Attribute", currencyTimeLimit=15)
public int getAge() {
return age;
}
}
有关详情,请参见this article.