jmx异常 management.NotCompliantMBeanException: MBean class com.style.springbootcore.jmx.Machines does

简单一个jmxdemo 居然报错。。。 看下完整信息

demo代码如下

public class JmxMain {
   public static void main(String[] args) {
      MBeanServer beanServer= ManagementFactory.getPlatformMBeanServer();
      ObjectName on;
      try {
         on = new ObjectName("com.style.springbootcore.jmx.Machines:type=machines");
         //MachineMBean为定义的mBean接口  Machines为MachineMBean 实现
         MachineMBean machineMBean = new Machines();
         beanServer.registerMBean(machineMBean ,on);
         //阻塞
         System.in.read();
      } catch (Exception e) {
         e.printStackTrace();
      }

   }
}

javax.management.NotCompliantMBeanException: MBean class com.style.springbootcore.jmx.Machines does not implement DynamicMBean, and neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class com.style.springbootcore.jmx.Machines is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: com.style.springbootcore.jmx.Machines: Class com.style.springbootcore.jmx.Machines is not a JMX compliant MXBean)
    at com.sun.jmx.mbeanserver.Introspector.checkCompliance(Introspector.java:176)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:317)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at com.style.springbootcore.jmx.JmxMain.main(JmxMain.java:19)

提示这Machines 该类没有实现动态mbean

解决办法

mbean的定义接口接口为MachineMBean  那么实现实现类 必须为去掉MBean后的名字 也就是Machine

原因:实现类的类名必须是 接口去掉MBean后的名字,且大小写敏感
例如:接口为 MachineMBean,则实现类类名为 Machine

修改后正常可以使用jconsole 进行访问 

你可能感兴趣的:(jmx)