Search This Blog

Friday, January 10, 2014

On-Demand Exporting a Spring Bean via JMX

1) Define the bean to be exported

 <bean id="myBean" class="...." />

2) Define a MBeanExporter

 <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter" />

2) Get the exporter

 ApplicationContext applicationContext = ...
 MBeanExporter beanExporter = (MBeanExporter) applicationContext.getBean("mbeanExporter");

3) Export the bean


4) Bean is now accessible via JMX

5) Unregister (if needed)

 beanExporter.unregisterManagedResource (ObjectName.getInstance(",name=User-A"));