gpt4 book ai didi

java - 标准 MBean 的描述

转载 作者:搜寻专家 更新时间:2023-10-31 20:06:28 25 4
gpt4 key购买 nike

我想让我的 Standard MBean 在 JBoss jmx-console 中变得冗长。 DynamicMBean 有 getMBeanInfo() 来完成它。方法返回带有 MBean 描述的 MBeanInfo。但是我怎样才能对 Standard MBean 做同样的事情呢?例如。我有以下 MBean 接口(interface):

public interface MyMBean {
String f();
}

... 实现如下:

public class My implements MyMBean {
public String f() {
return "test";
}
}

在这样的例子中应该如何添加描述?

谢谢

最佳答案

对于 StandardMBean,无法添加描述或其他元信息。

来自 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.

因此您至少需要使用 DynamicMBean(或 ModelMBean 或 OpenMBean)来指定此信息。 Spring 可以帮助您,因为它允许通过注释创建 DynamicMBean,最终使用起来比编写自己的 StandardMBean 更简单。示例(来自 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了解详情。

关于java - 标准 MBean 的描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5258603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com