原文章:http://lovespss.blog.51cto.com/1907593/616403
昨天同事在JBoss中部署MBean时一直报错:
Caused by: javax.management.NotCompliantMBeanException: Class does not expose a management interface: java.lang.Object
at org.jboss.mx.metadata.MBeanCapability.of(MBeanCapability.java:102)
at org.jboss.mx.metadata.MBeanCapability.of(MBeanCapability.java:100)
at org.jboss.mx.metadata.MBeanCapability.of(MBeanCapability.java:100)
at org.jboss.mx.metadata.MBeanCapability.of(MBeanCapability.java:100)
at org.jboss.mx.server.registry.BasicMBeanRegistry.registerMBean(BasicMBeanRegistry.java:182)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.server.MBeanServerImpl$3.run(MBeanServerImpl.java:1422)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.mx.server.MBeanServerImpl.registerMBean(MBeanServerImpl.java:1417)
at org.jboss.mx.server.MBeanServerImpl.registerMBean(MBeanServerImpl.java:1350)
at org.jboss.mx.server.MBeanServerImpl.createMBean(MBeanServerImpl.java:345)
at org.jboss.system.ServiceCreator.install(ServiceCreator.java:157)
at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:451)
at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:171)
... 81 more
几个人查了良久,试了能想到的一切方法,仍不得解。网上Google,Interface和实现必须放在同一个包内,改,再部署,仍报错。同事提了一句是不是要改成Sar包,改,再部署,仍旧报错。MBean命名有要求,实现类名必须是接口名去掉MBean,改,再部署,还是错措错!!!最后大家都已头昏眼花,不得不暂时作罢,次日再战。
今日一早起来,略读了《Java Management Extension》,书中 2.2.1节 Describing the Management Interface 正好讲到了NotCompliantMBeanException。遂一一对照,检查代码。
2.2.1.1 Pattern #1: Defining, naming, and implementing the MBean interface
接口必须定义成Public的。
public interface QueueMBean {
// management interface goes here. . .
}
实现类必须implements 接口的同时,名字也是大有讲究。假如接口名叫 XYZMBean ,那么实现名就必须一定是XYZ,而且是大小写敏感的。真是差之毫厘谬以NotCompliant。
public class Queue implements QueueMBean {
// implementation of QueueMBean
// and other stuff here. . .
}
再仔细一瞅同事的代码,顿悟。接口名去掉MBean后和实现类名差那么一个字母,怎么昨天我们三个人都没有看出来呢?把名字一改,再部署,OK了。