Yesterday I came across this question, but I managed to figure it out. I spent some time on this, so I thought this post would be useful for saving another time.
First you can register you beans in java code, as indicated in the message in the main method. But I think it is much easier if you use Spring.
Check out this link for more information; http://static.springsource.org/spring/docs/2.0.x/reference/jmx.html
There are some holes in the loop that you need to avoid. Do not start two MBeans servers in your application.
I used this configuration file:
<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="beans"> <map> <entry key="bean:name=beanName" value-ref="dataSource"/> </map> </property> <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/> </bean>
Use this configuration to attach the bean name to MBeanExporter. Make sure the lazy-init parameter is set to false. Please note that I am using this configuration in a web application. The web application is deployed inside tomcat. So, tomcat already has an MBean server. Therefore, you do not need to explicitly specify. If you run it offline, you need to start the MBean server and configure it accordingly.
Also note that you need to add the following properties inside the tomcat catalina.bat file. set CATALINA_OPTS = -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port = 8088 -Dcom.sun.management.jmxremote.ssl = false -Dcom.sun.management.jmxremote.authenticate = false -Dcom. sun.management.jmxremote.hostname = "local"
The Jmx connector port in this case is 8088, and the host name is "localhost". After you start tomcat, you need to start jconsole (I'm not going to tell you how to start it here). Then click “RemoteProcess” and enter “localhost: 8088” and connect to the tomcat MBean server. Then go to the MBean tab in jconsole and you will see your MBean.
source share