1

我正在尝试通过 spring 注释注册 mbeans。bean 在 jconsole 中正确显示,但类中定义的属性和方法没有显示。它出什么问题了?

例如,这是一个 mbean:

@ManagedResource(objectName="com.xormedia.aqua.mbean:name=AuthenticationServer",description="AuthenticationServerSummary")
public class AuthenticationServerSummaryMbean implements MonitorMXBean {
private String ip;
private String port;

@ManagedAttribute
public String getIp() {
    return ip;
}
public void setIp(String ip) {
    this.ip = ip;
}

@ManagedOperation(description="show port number")
public String getPort() {
    return port;
}
public void setPort(String port) {
    this.port = port;
}
}

我按照在线指南配置了spring xml,但只有mbeans,没有任何属性和方法的树结构。

像这样。没有属性和方法的mbean

4

1 回答 1

2

尝试将您的方法更改为以下内容:

添加<context:mbean-export/>你的弹簧配置。

稍微改变你的班级:

@ManagedResource(
        objectName = "com.xormedia.aqua.mbean:name=AuthenticationServer",
        description = "AuthenticationServerSummary",
        log = true,
        logFile = "jmx.log",
        currencyTimeLimit = 1)
public class AuthenticationServerSummaryMbean {
    private String ip;
    private String port;

    @ManagedAttribute(description = "IP Address", currencyTimeLimit = 1)
    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    @ManagedAttribute(description = "Port number", currencyTimeLimit = 1)
    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }
}

注册您的 mBean:

<bean id="mBeanService" class="yourpackage.AuthenticationServerSummaryMbean"/>
于 2013-08-30T08:51:47.140 回答