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 configure a
proxy for an MBean running in a local
MBeanServer:
<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 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 to cater 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"/> <property name="server" ref="clientConnector"/> </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 forward
all invocations to the MBeanServer via this
MBeanServerConnection.