Announcement Announcement Module
Collapse
No announcement yet.
Which MBeanServer is used? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Which MBeanServer is used?

    I am currently trying to expose a few methods via JMX.

    My context definition:

    Code:
        <bean id="oosTasksMBean" class="de.net22.oos.service.jmx.OosTasksMBeanImpl">
            <property name="jacStaticDataImportStrategy" ref="jacStaticDataImportStrategy"/>
            <property name="novasolStaticDataImportStrategy" ref="novasolStaticDataImportStrategy"/>
            <property name="interhomeStaticDataImportStrategy" ref="interhomeStaticDataImportStrategy"/>
        </bean>
    
    
        <bean id="mbeanServer"
              class="org.springframework.jmx.support.MBeanServerFactoryBean" />
    
        <!--
            this bean needs to be eagerly pre-instantiated in order for the exporting to occur;
            this means that it must not be marked as lazily initialized
        -->
        <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
            <property name="assembler" ref="assembler"/>
            <property name="namingStrategy" ref="namingStrategy"/>
            <property name="autodetect" value="false"/>
            <property name="server" ref="mbeanServer" />
            <property name="beans">
              <map>
                <entry key="bean:name=oosTasksMBean" value-ref="oosTasksMBean"/>
              </map>
            </property>
        </bean>
    
        <bean id="jmxAttributeSource"
              class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
    
        <!-- will create management interface using annotation metadata -->
        <bean id="assembler"
              class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
            <property name="attributeSource" ref="jmxAttributeSource"/>
        </bean>
    
        <!-- will pick up the ObjectName from the annotation -->
        <bean id="namingStrategy"
              class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
            <property name="attributeSource" ref="jmxAttributeSource"/>
        </bean>

    Registering the MBean with a server seems to work, as I can find this message in the logfile:

    Code:
    Located managed bean 'bean:name=oosTasksMBean': registering with JMX server as MBean [bean:name=oosTasksMBean]

    My problem is: I cannoct connect to the MBeanServer with a JMX console. I get a "connection refused" error.

    I have no idea which MBeanServer is used by Spring to expose the bean. I did not put any JMX imlementation on the classpath.

    Which server is used by Spring? How can I adjust the server's settings like credentials and passwords?

  • #2
    Add a JMX Connector Server

    I think the easiest long-term thing to do here is to specify to Spring that you want to expose your MBeans remotely by using the ConnectionServerFactoryBean as demonstrated in the Spring 2.5 Reference Manual under the section JSR-160 Connectors. You'll likely want to specify that Spring set up an rmiregistry as shown in that same section.

    You can find examples of this in several blogs entries including Remote JMX: With and Without Spring and Proxies (focus on the code listing for spring-server.xml) and Spring JMX Configuration with XML-Schema Based Configuration.

    A quicker solution (that I only use temporarily) is to start your Java main that bootstraps your Spring container with the system properties that expose the JMX MBeans remotely. You'll need to specify -Dcom.sun.management.jmxremote if running in J2SE 5, but not if running in J2SE 6. Then, you can also specify your other Remote JMX information in either J2SE 5 or Java SE 6 with these three system properties:

    Code:
    -Dcom.sun.management.jmxremote.port=1199
    -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.ssl=false
    Of course, you'd change the settings above to fit whatever you need. For example, you'd specify your own port by which you want clients to access your JMX MBeans. Also, the example above shows authentication turned off and SSL turned off. You can turn those on and require authentication and SSL support. However, for first connecting and getting it working, I like to turn that off.

    You can find additional details on these system parameters in the article Monitoring Local and Remote Applications Using JMX 1.2 and JConsole.

    In the long run, I prefer to specify the rmiregistry and JMX Connector Server information in my Spring XML configuration. However, using these system properties can be useful early on to make sure my code is working.

    Comment

    Working...
    X