问题描述
在远程机器上运行一个MBeanServer(如192.168.1.100),spring配置:<!--导出springbean所有的方法和属性不使用赖加载--><beanid="exporter"class="org.springframework.jmx.export.MBeanExporter"lazy-init="false"><!--需要导出为MBean的spring类--><propertyname="beans"><map><entrykey="Managed-Beans:name=appMonitorBean"value-ref="appMonitorBean"/><!--将JDMK定义的HtmlAdaptorServer的bean加入mbeanmap中--><entrykey="Managed-Beans:name=jdmkadapter,port=8099"value-ref="httpJDMKAdaptor"/><entrykey="Managed-Beans:name=mletLoader"value-ref="mletLoader"/></map></property><!--<propertyname="autodetect"value="true"/>--><!--指定export的MBeanserver--><propertyname="server"ref="mbeanServer"/></bean><beanid="appMonitorBean"class="cn.com.victorysoft.jmxmonitor.mbean.AppMonitorBean"></bean><!--配置类加载器--><beanid="mletLoader"class="javax.management.loading.MLet"></bean><beanid="mbeanServer"class="org.springframework.jmx.support.MBeanServerFactoryBean"/><!--定义JDMK的HtmlAdaptorServerbean--><beanid="httpJDMKAdaptor"class="com.sun.jdmk.comm.HtmlAdaptorServer"><propertyname="port"><value>8099</value></property></bean><!--注册端口我使用的是9992--><beanid="registry"class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"destroy-method="destroy"><propertyname="port"value="9992"/></bean><!--配置服务连接connectorviarmi--><beanid="serverConnector"class="org.springframework.jmx.support.ConnectorServerFactoryBean"depends-on="registry"><propertyname="objectName"value="connector:name=rmi"/><propertyname="serviceUrl"value="service:jmx:rmi:///jndi/rmi://192.168.1.100:9992/jmxrmi"/><propertyname="server"ref="mbeanServer"/><!--多线程启动connector,一个线程一个connector--><propertyname="threaded"value="true"/><!--多线程启动connector,threaddaemon--><propertyname="daemon"value="true"/></bean>启动192.168.1.100的服务,然后在192.168.1.110机器上远程向192.168.1.100服务器的MBeanServer注册MBean(HelloWorld.java):JMXServiceURLjmxUrl=newJMXServiceURL("service:jmx:rmi:///jndi/rmi://192.168.1.100:9992/jmxrmi");JMXConnectorconnector=JMXConnectorFactory.connect(jmxUrl);MBeanServerConnectionmBeanServerconnection=connector.getMBeanServerConnection();//在远程服务器上注册MBeanmBeanServerconnection.createMBean(HelloWorld.class.getName(),newObjectName("Managed-Beans:name=HelloWorldBean"));HelloWorld实现接口HelloWorldMBean,运行192.168.1.110机器上的MBean注册代码后报异常:Exceptioninthread"main"javax.management.ReflectionException:TheMBeanclasscouldnotbeloadedbythedefaultloaderrepositoryatcom.sun.jmx.mbeanserver.MBeanInstantiator.findClassWithDefaultLoaderRepository(MBeanInstantiator.java:71)atcom.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:259)atcom.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:199)atcom.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(JmxMBeanServer.java:286)atjavax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1382)atjavax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:72)atjavax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1265)atjavax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1360)atjavax.management.remote.rmi.RMIConnectionImpl.createMBean(RMIConnectionImpl.java:222)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atsun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)atsun.rmi.transport.Transport$1.run(Transport.java:159)atjava.security.AccessController.doPrivileged(NativeMethod)atsun.rmi.transport.Transport.serviceCall(Transport.java:155)atsun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)atsun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)atsun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)atjava.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)atjava.lang.Thread.run(Thread.java:662)atsun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)atsun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)atsun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)atcom.sun.jmx.remote.internal.PRef.invoke(UnknownSource)atjavax.management.remote.rmi.RMIConnectionImpl_Stub.createMBean(UnknownSource)atjavax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.createMBean(RMIConnector.java:627)atcn.com.victorysoft.jmxmonitor.mbean.TestRMI.main(TestRMI.java:84)Causedby:java.lang.ClassNotFoundException:cn.com.victorysoft.jmxmonitor.mbean.HelloWorldatcom.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(ClassLoaderRepositorySupport.java:211)atcom.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(ClassLoaderRepositorySupport.java:131)atcom.sun.jmx.mbeanserver.MBeanInstantiator.findClassWithDefaultLoaderRepository(MBeanInstantiator.java:68)atcom.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:259)atcom.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:199)atcom.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(JmxMBeanServer.java:286)atjavax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1382)atjavax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:72)atjavax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1265)atjavax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1360)atjavax.management.remote.rmi.RMIConnectionImpl.createMBean(RMIConnectionImpl.java:222)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atsun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)atsun.rmi.transport.Transport$1.run(Transport.java:159)atjava.security.AccessController.doPrivileged(NativeMethod)atsun.rmi.transport.Transport.serviceCall(Transport.java:155)atsun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)atsun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)atsun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)atjava.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)atjava.lang.Thread.run(Thread.java:662)请各位大侠解惑,问题出在什么地方?小弟不胜感激
解决方案
解决方案二:
顶起来,大牛们都现身吧,阿门
解决方案三:
在线等~~~~~
解决方案四:
人呢,有懂了大侠给解答下啊