4/08/2016

In spring container we might have defined many objects , how can we expose those beans in JMX console. JMX console is the utility provided by java so that we can monitor and access run time parameters. Lets create sample spring class that is going to registered as MBean.

@ManagedResource annotation tells the container this class going to act as Mbean. Now we have Mbean class which returns as message Hello, we need to register this class in MBean server. In order to register this class we need to create following entries in spring context xml.

Above class register all the MBean class into Mbean server. In order to access your MBean through JConsole we have to pass some JVM arguments when we run our program. In web based application we can set JRE arguments as like below.

Now we are ready with configuration start your server. Go to command prompt type jconsole.If your java home is set properly we can see following jconsole window.

Select local process if your server is running in locally or select remote proceess. Now type the following url 127.0.0.1:8845. No need to give user name and password click connect. As soon as connected we can see the class name is getting displayed. Now when we expand the class name it will give attributes and operations as options. Here operations means methods we defined in Mbean class,now if you click getMessage method it will return and says Hello.