by R4R Team

Integrating your beans to JMX:-
The core class in Spring’s JMX framework is the MBeanExporter. This class is responsible for taking your Spring beans and registering them with a JMX MBeanServer.
For example:

package org.springframework.jmx;

public class JmxTestBean implements IJmxTestBean {

private String name;

private int age;

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 an 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" lazy-init="false">

<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="60"/>

</bean>

</beans>

With this configuration the testBean bean is exposed as an MBean under the ObjectName bean:name=testBean1. By default, all public properties of the bean are exposed as attributes and all public methods are exposed as operations.

Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!