如何将JMX集成到tomcat应用程序或我做错了什么?

时间:2015-08-11 11:33:09

标签: jmx spring-jmx

我尝试配置JMX没有运气..我做了什么?

  1. 创建的课程:

    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();
        }
    }
    
  2. 之后我又按照以下几行添加到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>
    
  3. 作为最后一步,我尝试将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).
    
  4. 我做错了什么?

0 个答案:

没有答案