Announcement Announcement Module
No announcement yet.
Which MBeanServer is used? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

        <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 id="mbeanServer"
              class="" />
            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">
                <entry key="bean:name=oosTasksMBean" value-ref="oosTasksMBean"/>
        <bean id="jmxAttributeSource"
        <!-- will create management interface using annotation metadata -->
        <bean id="assembler"
            <property name="attributeSource" ref="jmxAttributeSource"/>
        <!-- will pick up the ObjectName from the annotation -->
        <bean id="namingStrategy"
            <property name="attributeSource" ref="jmxAttributeSource"/>

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

    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 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:

    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.