Diary of a (not so) lazy Java Developer coping with Java SE, Jave EE, ORM, Spring and the idiosyncrasy of IT.
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
beanExporter.registerManagedResource(applicationContext.getBean("myBean"),
ObjectName.getInstance("com.company:type=Users,name=User-A"));
4) Bean is now accessible via JMX
5) Unregister (if needed)
beanExporter.unregisterManagedResource (ObjectName.getInstance("com.company:type=Users,name=User-A"));
Subscribe to:
Posts (Atom)