似乎我的班级是一个内部阶级的事实导致了这个问题,这是我的预感 - 但基本上它是通常的模式:
public class UserProvisionerProfiler implements UserProvisionerProfilerMBean {
@Override
public int getTotalNumberOfUsers() {
return activeClients.size();
}
}
Run Code Online (Sandbox Code Playgroud)
和接口(嵌套在一个更大的类):
public interface UserProvisionerProfilerMBean {
public int getTotalNumberOfUsers();
}
Run Code Online (Sandbox Code Playgroud)
在代码中注册:
UserProvisionerProfiler userProvisionerProfiler = new UserProvisionerProfiler();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName(userProvisionerProfiler.getClass().getPackage().getName() + ":type=" + userProvisionerProfiler.getClass().getName());
mbs.registerMBean(userProvisionerProfiler, name);
Run Code Online (Sandbox Code Playgroud)
而错误:
1356 [1;31mERROR[39m [main], UserProvisioner ; Unhandled exception caught in main()
javax.management.NotCompliantMBeanException: MBean class UserProvisioner$UserProvisionerProfiler does not implement DynamicMBean, and neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class UserProvisioner$UserProvisionerProfiler is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: UserProvisioner$UserProvisionerProfiler: Class UserProvisioner$UserProvisionerProfiler is not a JMX compliant MXBean)
at com.sun.jmx.mbeanserver.Introspector.checkCompliance(Introspector.java:171)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:317)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:512)
UserProvisioner.registerThisAsMBean(UserProvisioner.java:734)
UserProvisioner.start(UserProvisioner.java:797)
UserProvisioner.main(UserProvisioner.java:844)
Run Code Online (Sandbox Code Playgroud)
我没有成功找到一个更严格的兼容MBean定义读取JMX规范或代码,所以我想知道我是否可以打捞内部类或者是否必须将其分离出来,或者是否有什么东西否则我错过了.
JB-*_*JB- 16
根据JMX规范,标准MBean必须由两部分组成:
由于这些限制,当且仅当MBean接口也是同一个包含类的静态内部类时,静态内部类才可以是MBean实现.