Exporting an MBean in a Spring context

Now, we need to create an MBeanExporter in a Spring application context. We just need to add the following tag in the Spring context XML configuration:

<context:mbean-export/>
We need to add the component-scan element before the ‹context:mbean-export/› element; otherwise, the JMX server will not be able to find any beans.

So, our Spring context configuration will look like the following:

<?xml version="1.0" encoding="UTF-8"?>
<beans><!-- Skipped schema definitions -->

<context:component-scan base-
package="com.packt.springhighperformance.ch4.mbeans" />

<context:mbean-export/>

</beans>

Now, we just need to start our Tomcat server and open the JConsole to see our MBean. After connecting to JConsole, go to the MBeans tab, where you can see our package folder, which contains our BankMoneyTransferService MBean, listed in the sidebar:

As you can see in the earlier example, our MBean is generated and listed in the JConsole. Now, we can transfer an amount from one account to another by clicking on the Transfer button, invoking the method transfer(), which we created in our MBean. When we click on the checkBalance button, it will show the current balance in a pop up based on the entered account number. In the background, it will invoke the checkBalance() method of the BankMoneyTransferService class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset