我尝试配置 JMX,但没有成功。我做了什么?
创建类:
public class JmxTestBean implements IJmxTestBean { private String name; private int age; private boolean isSuperman; public int getAge() { return age; } public void setAge(int age) { this.age = age; } public void setName(String name) { this.name = name; } public String getName() { return name; } public int add(int x, int y) { return x + y; } public void dontExposeMe() { throw new RuntimeException(); } }
之后,我在 spring 配置中添加了以下几行:
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/> <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"> <property name="beans"> <map> <entry key="bean:name=testBean1" value-ref="testBean"/> </map> </property> <property name="server" ref="mbeanServer"/> </bean> <bean id="testBean" class="com.db.gbs.jmx.simulator.JmxTestBean"> <property name="name" value="TEST"/> <property name="age" value="100"/> </bean>
作为最后一步,我尝试如下设置 env 变量:
set CATALONA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010"
并启动tomcat7:
mvn jetty:run-exploded -Dorg.eclipse.jetty.server.Request.maxFormContentSize=100000000
使用 JConsole 尝试连接并收到以下错误:
Could not connect to localhost:9010 : Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: java.net.ConnectException: Connection refused: connect] Could not connect to localhost:9010. Make sure the JVM is running and that you are using the correct protocol in the Service URL service:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi).
我做错了什么?