Chapter 19. JMX Support

19.1. Introduction

The JMX support in Spring provides you with the features to easily and transparently integrate your Spring application into a JMX infrastructure. Specifically, Spring JMX provides 4 core features:

  • Automatic Registration of any Spring bean as a JMX MBean

  • Flexible mechanism for controlling the management interface of your beans

  • Declarative exposure of MBeans over remote, JSR-160 connectors

  • Simple proxying of both local and remote MBean resources

These features are designed to work without coupling your application components to either Spring or JMX interfaces and classes. Indeed, for the most part your application classes need not be aware of either Spring or JMX in order to take advantage of the Spring JMX features.

19.2. Exporting your Beans to JMX

The core class in the Spring JMX framework is the MBeanExporter. This class is responsible for taking your Spring beans and registering them with the JMX MBeanServer. For example, consider the simple bean class shown below:

package org.springframework.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();
    }

}

To expose the properties and methods of this bean as attributes and operations of a JMX MBean you simply configure an instance of the MBeanExporter class in your configuration file and pass in the bean as shown below:

<beans>

  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
      <map>
        <entry key="bean:name=testBean1" value-ref="testBean"/>
      </map>
    </property>
  </bean>

  <bean id="testBean" class="org.springframework.jmx.JmxTestBean">
    <property name="name" value="TEST"/>
    <property name="age" value="100"/>
  </bean>

</beans>

Here, the important definition is the exporter bean. The beans property is used to tell the MBeanExporter which of your beans should be exported to the JMX MBeanServer. The beans property is of type Map, and thus you use the <map> and <entry> tags to configure the beans to be exported. In the default configuration, the key of an entry in of the Map is used as the ObjectName for the bean that is the value of that entry. This behaviour can be changed as described in section Section 19.4, “Controlling the ObjectNames for your Beans”.

With this configuration the testBean bean is exposed as a JMX MBean under the ObjectName bean:name=testBean1. All public properties of the bean are exposed as attributes and all public methods (expect those defined in Object) are exposed as operations.

19.2.1. Creating an MBeanServer

The configuration shown above assumes that the application is running in an environment that has one and only one MBeanServer already running. In this case, Spring will locate the running MBeanServer and register your beans with that. This is useful when your application is running inside a container such as Tomcat or IBM WebSphere that has its own MBeanServer.

However, this approach is of no use in a standalone environment, or when running inside a container that does not provide an MBeanServer. To overcome this you can create an MBeanServer instance declaratively by adding an instance of org.springframework.jmx.support.MBeanServerFactoryBean to your configuration. You can also ensure that this MBeanServer is used by using MBeanServerFactoryBean to set the server property of the MBeanExporter. This is shown below:

<beans>

  <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="org.springframework.jmx.JmxTestBean">
    <property name="name" value="TEST"/>
    <property name="age" value="100"/>
  </bean>

</beans>

Here an instance of MBeanServer is created by the MBeanServerFactoryBean and is supplied to the MBeanExporter via the server property. When you supply your own MBeanServer, MBeanExporter will not attempt to locate a running MBeanServer. For this to work correctly, you must have a JMX implementation on your classpath.

19.2.2. Lazy-Initialized MBeans

If you configure a bean with the MBeanExporter that is also configured for lazy initialization, then the MBeanExporter will NOT break this contract and will avoid instantiating the bean. Instead, it will register a proxy with the MBeanServer and will defer obtaining the bean from the BeanFactory until the first invocation on the proxy occurs.

19.2.3. Automatic Registration of MBeans

Any beans that are exported through the MBeanExporter and are already valid MBeans are registered as is with the MBeanServer without further intervention from Spring. MBeans can be automatically detected by the MBeanExporter by setting the autodetect property to true:

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
  <property name="autodetect" value="true"/>
</bean>

<bean name="spring:mbean=true" class="org.springframework.jmx.export.TestDynamicMBean"/>

Here, the bean called spring:mbean=true is already a valid JMX MBean and will be automatically registered by Spring. By default, beans that are autodetected for JMX registration have their bean name used as the ObjectName. This behavior can be overridden as detailed in section Section 19.4, “Controlling the ObjectNames for your Beans”.

19.3. Controlling the Management Interface of Your Beans

In the previous example, you had little control over the management interface of your bean with all the public properties and methods being exposed. To solve this problem, Spring JMX provides a comprehensive and extensible mechanism for controlling the management interfaces of your beans.

19.3.1. The MBeanInfoAssembler Interface

Behind the scenes, the MBeanExporter delegates to an implementation of the org.springframework.jmx.export.assembler.MBeanInfoAssembler interface which is responsible for defining the management interface of each bean that is being exposed. The default implementation, org.springframework.jmx.export.assembler.SimpleReflectiveMBeanInfoAssembler, simply defines an interface that exposes all public properties and methods as you saw in the previous example. Spring provides two additional implementations of the MBeanInfoAssembler interface that allow you to control the management interface using source level metadata or any arbitrary interface.

19.3.2. Using Source-Level Metadata

Using the MetadataMBeanInfoAssembler you can define the management interfaces for your beans using source level metadata. The reading of metadata is encapsulated by the org.springframework.jmx.export.metadata.JmxAttributeSource interface. Out of the box, Spring JMX provides support for two implementations of this interface: org.springframework.jmx.export.metadata.AttributesJmxAttributeSource for Commons Attributes and org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource for JDK 5.0 annotations. The MetadataMBeanInfoAssembler MUST be configured with an implementation of JmxAttributeSource for it to function correctly. For this example, we will use the Commons Attributes metadata approach.

To mark a bean for export to JMX, you should annotate the bean class with the ManagedResource attribute. In the case of the Commons Attributes metadata approach this class can be found in the org.springframework.jmx.metadata package. Each method you wish to expose as an operation should be marked with a ManagedOperation attribute and each property you wish to expose should be marked with a ManagedAttribute attribute. When marking properties you can omit either the getter or the setter to create a write-only or read-only attribute respectively.

The example below shows the JmxTestBean class that you saw earlier marked with Commons Attributes metadata:

package org.springframework.jmx;

/**
 * @@org.springframework.jmx.export.metadata.ManagedResource
 *  (description="My Managed Bean", objectName="spring:bean=test",
 *  log=true, logFile="jmx.log", currencyTimeLimit=15, persistPolicy="OnUpdate",
 *  persistPeriod=200, persistLocation="foo", persistName="bar")
 *
 */
public class JmxTestBean implements IJmxTestBean {

  private String name;

  private int age;

  /**
   * @@org.springframework.jmx.export.metadata.ManagedAttribute
   *   (description="The Age Attribute", currencyTimeLimit=15)
   */
  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }

  /**
   * @@org.springframework.jmx.export.metadata.ManagedAttribute
   *  (description="The Name Attribute",  currencyTimeLimit=20,
   *   defaultValue="bar", persistPolicy="OnUpdate")
   */
  public void setName(String name) {
    this.name = name;
  }

  /**
   * @@org.springframework.jmx.export.metadata.ManagedAttribute
   *   (defaultValue="foo", persistPeriod=300)
   */
  public String getName() {
    return name;
  }


  /**
   * @@org.springframework.jmx.export.metadata.ManagedOperation
   *  (description="Add Two Numbers Together")
   */
  public int add(int x, int y) {
    return x + y;
  }

  public void dontExposeMe() {
    throw new RuntimeException();
  }
}

Here you can see that the JmxTestBean class is marked with the ManagedResource attribute and that this ManagedResoure attribute is configured with a set of properties. These properties can be used to configure various aspects of the MBean that is generated by the MBeanExporter and are explained in greater detail later in section Section 19.3.4, “Source-Level Metadata Types”.

You will also notice that both the age and name properties are marked with the ManagedAttribute attribute but in the case of the age property, only the getter is marked. This will cause both of these properties to be included in the management interface as attributes, and for the age attribute to be read-only.

Finally, you will notice that the add(int, int) method is marked with the ManagedOperation attribute whereas the dontExposeMe() method is not. This will casue the management interface to contain only one operation, add(int, int), when using the MetadataMBeanInfoAssembler.

The code below shows how you configure the MBeanExporter to use the MetadataMBeanInfoAssembler:

<beans>

  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
      <map>
        <entry key="bean:name=testBean1">
          <ref local="testBean"/>
        </entry>
      </map>
    </property>
    <property name="assembler">
      <ref local="assembler"/>
    </property>
  </bean>

  <bean id="testBean" class="org.springframework.jmx.JmxTestBean">
    <property name="name">
      <value>TEST</value>
    </property>
    <property name="age">
      <value>100</value>
    </property>
  </bean>

  <bean id="attributeSource"
        class="org.springframework.jmx.export.metadata.AttributesJmxAttributeSource">
    <property name="attributes">
      <bean class="org.springframework.metadata.commons.CommonsAttributes"/>
    </property>
  </bean>

  <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    <property name="attributeSource">
      <ref local="attributeSource"/>
    </property>
  </bean>

</beans>

Here you can see that a MetadataMBeanInfoAssembler bean has been configured with an instance of AttributesJmxAttributeSource and passed to the MBeanExporter through the assembler property. This is all that is required to take advantage of metadata-driven management interfaces for your Spring-exposed MBeans.

19.3.3. Using JDK 5.0 Annotations

To enable the use of JDK 5.0 annotations for management interface definition, Spring provides a set of annotations that mirror the Commons Attribute attribute classes and an implementation of JmxAttributeSource, AnnotationsJmxAttributeSource, that allows the MBeanInfoAssembler to read them.

The example below shows a bean with a JDK 5.0 annotation defined management interface:

package org.springframework.jmx;

import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedAttribute;

@ManagedResource(objectName="bean:name=testBean4", description="My Managed Bean", log=true,
    logFile="jmx.log", currencyTimeLimit=15, persistPolicy="OnUpdate", persistPeriod=200,
    persistLocation="foo", persistName="bar")
public class AnnotationTestBean implements IJmxTestBean {

   private String name;

  private int age;

  @ManagedAttribute(description="The Age Attribute", currencyTimeLimit=15)
  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }

  @ManagedAttribute(description="The Name Attribute",
      currencyTimeLimit=20,
      defaultValue="bar",
      persistPolicy="OnUpdate")
  public void setName(String name) {
    this.name = name;
  }

  @ManagedAttribute(defaultValue="foo", persistPeriod=300)
  public String getName() {
    return name;
  }

  @ManagedOperation(description="Add Two Numbers Together")
  public int add(int x, int y) {
    return x + y;
  }

  public void dontExposeMe() {
    throw new RuntimeException();
  }
}

As you can see little has changed, other than the basic syntax of the metadata definitions. Behind the scenes this approach is a little slower at startup because the JDK 5.0 annotations are converted into the classes used by Commons Attributes. However, this is only a one-off cost and JDK 5.0 annotations give you the benefit of compile-time checking.

19.3.4. Source-Level Metadata Types

The following source level metadata types are available for use in Spring JMX:

Table 19.1. Source-Level Metadata Types

PurposeCommons Attributes AttributeJDK 5.0 AnnotationAttribute / Annotation Type
Mark all instances of a Class as JMX managed resourcesManagedResource@ManagedResourceClass
Mark a method as a JMX operationManagedOperation@ManagedOperationMethod
Mark a getter or setter as one half of a JMX attributeManagedAttribute@ManagedAttributeMethod (only getters and setters)
Define descriptions for operation parametersManagedOperationParameter@ManagedOperationParameter and @ManagedOperationParametersMethod

The following configuration parameters are available for use on these source-level metadata types:

Table 19.2. Source-Level Metadata Parameters

ParameterDescriptionApplies to
objectNameUsed by MetadataNamingStrategy to determine the ObjectName of a managed resourceManagedResource
descriptionSets the friendly description of the resource, attribute or operationManagedResource, ManagedAttribute, ManagedOperation, ManagedOperationParameter
currencyTimeLimitSets the value of the currencyTimeLimit descriptor fieldManagedResource, ManagedAttribute
defaultValueSets the value of the defaultValue descriptor fieldManagedAttribute
logSets the value of the log descriptor fieldManagedResource
logFileSets the value of the logFile descriptor fieldManagedResource
persistPolicySets the value of the persistPolicy descriptor fieldManagedResource
persistPeriodSets the value of the persistPeriod descriptor fieldManagedResource
persistLocationSets the value of the persistLocation descriptor fieldManagedResource
persistNameSets the value of the persistName descriptor fieldManagedResource
nameSets the display name of an operation parameterManagedOperationParameter
indexSets the index of an operation parameterManagedOperationParameter

19.3.5. The AutodetectCapableMBeanInfoAssembler Interface

To simply configuration even further, Spring introduces the AutodetectCapableMBeanInfoAssembler interface which extends the MBeanInfoAssembler interface to add support for autodetection of MBean resources. If you configure the MBeanExporter with an instance of AutodetectCapableMBeanInfoAssembler then it is allowed to "vote" on the inclusion of beans for exposure to JMX.

Out of the box, the only implementation of AutodetectCapableMBeanInfo is the MetadataMBeanInfoAssembler which will vote to include any bean which is marked with the ManagedResource attribute. The default approach in this case is to use the bean name as the ObjectName which results in a configuration like this:

<beans>

  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="assembler" ref="assembler"/>
	  <property name="autodetect" value="true"/>
  </bean>

  <bean id="bean:name=testBean1" class="org.springframework.jmx.JmxTestBean">
    <property name="name" value="TEST"/>
    <property name="age" value="100"/>
  </bean>

  <bean id="attributeSource"
      class="org.springframework.jmx.export.metadata.AttributesJmxAttributeSource"/>

  <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    <property name="attributeSource" ref="attributeSource"/>
  </bean>

</beans>

Notice that in this configuration no beans are passed to the MBeanExporter, however the JmxTestBean will still be registered since it is marked with the ManagedResource attribute and the MetadataMBeanInfoAssembler detects this and votes to include it. The only problem with this approach is that the name of the JmxTestBean now has business meaning. You can solve this problem by changing the default behavior for ObjectName creation as defined in section Section 19.4, “Controlling the ObjectNames for your Beans”.

19.3.6. Defining Management Interfaces using Java Interfaces

In addition to the MetadataMBeanInfoAssembler, Spring also includes the InterfaceBasedMBeanInfoAssembler which allows you to constrain the methods and properties that are exposed based on the set of methods defined in a collection of interfaces.

Although the standard mechanism for exposing MBeans is to use interfaces and a simple naming scheme, the InterfaceBasedMBeanInfoAssembler extends this functionality by removing the need for naming conventions, allowing you to use more than one interface and removing the need for your beans to implement the MBean interfaces.

Consider this interface that is used to define a management interface for the JmxTestBean class that you saw earlier:

public interface IJmxTestBean {

  public int add(int x, int y);

  public long myOperation();

  public int getAge();

  public void setAge(int age);

  public void setName(String name);

  public String getName();
}

This interface defines the methods and properties that will be exposed as operations and attributes on the JMX MBean. The code below shows how to configure Spring JMX to use this interface as the definition for the management interface:

<beans>

  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
      <map>
        <entry key="bean:name=testBean5">
          <ref local="testBean"/>
        </entry>
      </map>
    </property>
    <property name="assembler">
      <bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
        <property name="managedInterfaces">
          <value>org.springframework.jmx.IJmxTestBean</value>
        </property>
      </bean>
    </property>
  </bean>

  <bean id="testBean" class="org.springframework.jmx.JmxTestBean">
    <property name="name">
      <value>TEST</value>
    </property>
    <property name="age">
      <value>100</value>
    </property>
  </bean>

</beans>

Here you can see that the InterfaceBasedMBeanInfoAssembler is configured to use the IJmxTestBean interface when constructing the management interface for any bean. It is important to understand that beans processed by the InterfaceBasedMBeanInfoAssembler are NOT required to implement the interface used to generate the JMX management interface.

In the case above, the IJmxTestBean interface is used to construct all management interfaces for all beans. In many cases this is not the desired behavior and you may want to use different interfaces for different beans. In this case, you can pass InterfaceBasedMBeanInfoAssembler a Properties via the interfaceMappings property, where the key of each entry is the bean name and the value of each entry is a comma-seperated list of interface names to use for that bean.

If no management interface is specified through either the managedInterfaces or interfaceMappings properties, then InterfaceBasedMBeanInfoAssembler will reflect on the bean and use all interfaces implemented by that bean to create the management interface.

19.3.7. Using MethodNameBasedMBeanInfoAssembler

The MethodNameBasedMBeanInfoAssembler allows you to specify a list of method names that will be exposed to JMX as attributes and operations. The code below shows a sample configuration for this:

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
      <map>
        <entry key="bean:name=testBean5">
          <ref local="testBean"/>
        </entry>
      </map>
    </property>
    <property name="assembler">
      <bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler">
        <property name="managedMethods">
          <value>add,myOperation,getName,setName,getAge</value>
        </property>
      </bean>
    </property>
</bean>

Here you can see that the methods add and myOperation will be exposed as JMX operations and getName, setName and getAge will be exposed as the appropriate half of a JMX attribute. In the code above, the method mappings apply to beans that are exposed to JMX. To control method exposure on a bean by bean basis, use the methodMappings property of MethodNameMBeanInfoAssembler to map bean names to lists of method names.

19.4. Controlling the ObjectNames for your Beans

Behind the scenes, the MBeanExporter delegates to an implementation of the ObjectNamingStrategy to obtain ObjectNames for each of the beans it is registering. The default implementation, KeyNamingStrategy, will, by default, use the key of the beans Map as the ObjectName. In addition, the KeyNamingStrategy can map the key of the beans Map to an entry in a Properties file (or files) to resolve the ObjectName. In addition to the KeyNamingStrategy, Spring provides two additional ObjectNamingStrategy implementations: IdentityNamingStrategy that builds an ObjectName based on the identity of the bean and MetadataNamingStrategy that uses the source level metadata to obtain the ObjectName.

19.4.1. Reading ObjectNames from Properties

You can configure your own KeyNamingStrategy instance and configure it to read ObjectNames from a Properties instance rather than use bean key. The KeyNamingStrategy will attempt to locate an entry in the Properties with a key corresponding to the bean key. If no entry is found or if the Properties instance is null then the bean key itself is used.

The code below shows a sample configuration for the KeyNamingStrategy:

<beans>

  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
      <map>
        <entry key="testBean" value-ref="testBean"/>
      </map>
    </property>
    <property name="namingStrategy" ref="namingStrategy"/>
  </bean>

  <bean id="testBean" class="org.springframework.jmx.JmxTestBean">
    <property name="name" value="TEST"/>
    <property name="age" value="100"/>
  </bean>

  <bean id="namingStrategy" class="org.springframework.jmx.export.naming.KeyNamingStrategy">
    <property name="mappings">
      <props>
        <prop key="testBean">bean:name=testBean1</prop>
      </props>
    </property>
    <property name="mappingLocations">
      <value>names1.properties,names2.properties</value>
    </property>
  </bean

</beans>

Here an instance of KeyNamingStrategy is configured with a Properties instance that is merged from the Properties instance defined by the mapping property and the properties files located in the paths defined by the mappings property. In this configuration, the testBean bean will be given the ObjectName bean:name=testBean1 since this is the entry in the Properties instance that has a key corresponding to the bean key.

If no entry in the Properties instance can be found then the bean key is used as the ObjectName.

19.4.2. Using the MetadataNamingStrategy

The MetadataNamingStrategy uses objectName property of the ManagedResource attribute on each bean to create the ObjectName. The code below shows the configuration for the MetadataNamingStrategy:

<beans>

  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
      <map>
        <entry key="testBean" value-ref="testBean"/>
      </map>
    </property>
    <property name="namingStrategy" ref="namingStrategy"/>
  </bean>

  <bean id="testBean" class="org.springframework.jmx.JmxTestBean">
    <property name="name" value="TEST"/>
    <property name="age" value="100"/>
  </bean>

  <bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
    <property name="attributeSource" ref="attributeSource"/>
  </bean>

  <bean id="attributeSource"
      class="org.springframework.jmx.export.metadata.AttributesJmxAttributeSource"/>

</beans>

19.5. Exporting your Beans with JSR-160 Connectors

For remote access, Spring JMX module offers two FactoryBean implementations inside the org.springframework.jmx.support package for creating server-side and client-side connectors.

19.5.1. Server-side Connectors

To have Spring JMX create,start and expose a JSR-160 JMXConnectorServer use the following configuration:

<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean"/>

By default ConnectorServerFactoryBean creates a JMXConnectorServer bound to "service:jmx:jmxmp://localhost:9875". The serverConnector bean thus exposes the local MBeanServer to clients through the JMXMP protocol on localhost, port 9875. Note that the JMXMP protocol is marked as optional by the JSR 160: Currently, the main open-source JMX implementation, MX4J, and the one provided with J2SE 5.0 do not support JMXMP.

To specify another URL and register the JMXConnectorServer itself with the MBeanServer use the serviceUrl and objectName properties respectively:

<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
  <property name="objectName" value="connector:name=rmi"/>
  <property name="serviceUrl" 
               value"service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector"/>
</bean>

If the objectName property is set Spring will automatically register your connector with the MBeanServer under that ObjectName. The example below shows the full set of parameters which you can pass to the ConnectorServerFactoryBean when creating the JMXConnector:

<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
  <property name="objectName" value="connector:name=iiop"/>
  <property name="serviceUrl" 
               value="service:jmx:iiop://localhost/jndi/iiop://localhost:900/myconnector"/>
  <property name="threaded" value="true"/>
  <property name="daemon" value="true"/>
  <property name="environment">
    <map>
      <entry key="someKey" value="someValue"/>
    </map>
  </property>
</bean>

For more information on these properties consult the JavaDoc. For information of meaning of the environment variables, consult the JavaDoc for

Note that when using a RMI-based connector you need the lookup service (tnameserv or rmiregistry) to be started in order for the name registration to complete. If you are using Spring to export remote services for you via RMI, then Spring will already have constructed an RMI registry. If not, you can easily start a registry using the following snippet of configuration:

<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
  <property name="port" value="1099"/>
</bean>

19.5.2. Client-side Connectors

To create an MBeanServerConnection to a remote JSR-160 enabled MBeanServer use the MBeanServerConnectionFactoryBean as shown below:

<bean id="clientConnector" class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
  <property name="serviceUrl" value="service:jmx:rmi://localhost:9875"/>
</bean>

19.5.3. JMX over Burlap/Hessian/SOAP

JSR-160 permits extensions to the way in which communication is done between the client and the server. The examples above are using the mandatory RMI-based implementation required by the JSR-160(IIOP and JRMP) and the optional JMXMP. By using other providers or implementations like MX4J you can take advantage of protocols like SOAP, Hessian, Burlap over simple HTTP or SSL and other:

<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
  <property name="objectName" value="connector:name=burlap"/>
  <property name="serviceUrl" value="service:jmx:burlap://localhost:9874"/>
</bean>

For this example, MX4J 3.0.0 was used. See the official MX4J documentation for more information.

19.6. Accessing MBeans via Proxies

Spring JMX allows you to create proxies that re-route calls to MBeans registered in a local or remote MBeanServer. These proxies provide you with a standard Java interface through which you can interact with your MBeans. The code below shows how to to configure a proxy for an MBean running in the local MBeanServer:

<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
    <property name="objectName">
      <value>bean:name=testBean</value>
    </property>
    <property name="proxyInterface">
      <value>org.springframework.jmx.IJmxTestBean</value>
    </property>
</bean>

Here you can see that a proxy is created for the MBean registered under the ObjectName: bean:name=testBean. The set of interfaces that the proxy will implement is controlled by the proxyInterfaces property and the rules for mapping methods and properties on these interfaces to operations and attributes on the MBean are the same rules used by the InterfaceBasedMBeanInfoAssembler.

The MBeanProxyFactoryBean can create a proxy to any MBean that is accessible via an MBeanServerConnection. By default, the local MBeanServer is located and used, but you can override this and provide an MBeanServerConnection pointing to a remote MBeanServer allowing for proxies pointing to remote MBeans:

<bean id="clientConnector" class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
  <property name="serviceUrl" value="service:jmx:rmi://remotehost:9875"/>
</bean>

<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
  <property name="objectName" value="bean:name=testBean"/>
  <property name="proxyInterface" value="org.springframework.jmx.IJmxTestBean"/>
</bean>

Here you can see that we create an MBeanServerConnection pointing to a remote machine using the MBeanServerConnectionFactoryBean. This MBeanServerConnection is then passed to the MBeanProxyFactoryBean via the server property. The proxy that is created will pass on all invocations to the MBeanServer via this MBeanServerConnection.