1.MBean 接口的命名一定要以MBean或MXBean结尾,否则报:
Exception in thread “main” javax.management.NotCompliantMBeanException: MBean class com.example.mbeans.Hello does not implement DynamicMBean, neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class com.example.mbeans.Hello is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: com.example.mbeans.Hello: Class com.example.mbeans.Hello is not a JMX compliant MXBean)
at com.sun.jmx.mbeanserver.Introspector.checkCompliance(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source)
at com.example.mbeans.Main.main(Main.java:28)
Exception in thread “main” javax.management.NotCompliantMBeanException: MBean class com.example.mbeans.Hello does not implement DynamicMBean, neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class com.example.mbeans.Hello is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: com.example.mbeans.Hello: Class com.example.mbeans.Hello is not a JMX compliant MXBean)
at com.sun.jmx.mbeanserver.Introspector.checkCompliance(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source)
at com.example.mbeans.Main.main(Main.java:28)
2.Server start前必须用 rmiregistry 9999 注册端口,或者LocateRegistry.createRegistry(9999);
3.使用Subject Delegation(使用java.policy)来控制权限,不能在eclipse执行Server,
因为jvm会任务bin目录也是一个Protected Domain,这样没有包含权限。
access: domain that failed ProtectionDomain (file:/D:/code/jmx_examples/bin/ <no signer certificates>)
sun.misc.Launcher$AppClassLoader@e48e1b
<no principals>
4.access.properties控制访问权限
样例:
username readwrite create SimpleStandard unregister
password.properties控制用户和密码
样例:
username password
5.MXBean 和MBean的区别在于MBean指定定义基本类型参数的接口,MXBean可以是复杂对象参数的接口。