JConsole没有显示我在mbean中定义的mbean属性和方法

时间:2013-08-30 08:27:29

标签: java spring jmx jconsole spring-jmx

我正试图通过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 without attributes and methods

1 个答案:

答案 0 :(得分:1)

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

在弹簧配置中添加<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"/>