似乎我的班级是内部班级这一事实导致了这个问题,这是我的预感 - 但基本上这是通常的模式:
public class UserProvisionerProfiler implements UserProvisionerProfilerMBean {
@Override
public int getTotalNumberOfUsers() {
return activeClients.size();
}
}
和接口(嵌套在一个更大的类中):
public interface UserProvisionerProfilerMBean {
public int getTotalNumberOfUsers();
}
在代码中注册:
UserProvisionerProfiler userProvisionerProfiler = new UserProvisionerProfiler();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName(userProvisionerProfiler.getClass().getPackage().getName() + ":type=" + userProvisionerProfiler.getClass().getName());
mbs.registerMBean(userProvisionerProfiler, name);
和错误:
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)
除了阅读 JMX 规范或代码之外,我在找到更严格的兼容 MBean 定义方面收效甚微,所以我想知道是否可以挽救内部类,或者是否必须将其分离出来,或者是否有什么东西否则我失踪了。