原文章: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了。