The JMX specification defines an architecture for monitoring and management of Java software components. To expose a Spring bean as a MBean object please have a look at the following example. The MBeanExporter class represents the base class for exposing of Spring beans. It references a MBeanServer and a list of spring beans have to be exported.
Classes and interfaces:
public interface IProcess {
public doProcess(int id);
}
public class Process implements IProcess {
public doProcess(int id) {
//triggering of a business logic
}
}
Instrumentalization:
<beans>
<!-- instancing your business logic class -->
<bean id="businessLogicComponent" class="org.developers.blog.example.spring.Process"/>
<!-- get the PlatformMBeanServer -->
<bean id="mbeanServer" class="java.lang.management.ManagementFactory" factory-method="getPlatformMBeanServer"/>
<!-- exports spring components / beans -->
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="server" ref="mbeanServer"/>
<property name="beans">
<map>
<entry key="bean:name=process1" value-ref="businessLogicComponent"/>
</map>
</property>
<!-- how to propagate meta information -->
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
<property name="managedInterfaces">
<value>org.developers.blog.example.spring.IProcess</value>
</property>
</bean>
</property>
</bean>
</beans>
Technorati Tags: Spring Spring JMX JMX
