I'm new to JMX and have been reading online articles to understand Spring support for MBeans.
I have a simple class HelloWorld shown below which I have exposed as MBean. This works well. The 'name' is displayed as an attribute for my bean and I am able to invoke the operations get/set for the 'name' property.
Now I'd like to take it further with my complex type 'myProperties'. I'd like for each entry in the map 'myProperties' to be exposed as an attribute in the JMX Console.
I found some code online that tells me how this can be done, but I'm looking for a way to do this in spring.
http://weblogs.java.net/blog/emcmanu...l_example.html
Can this be done?
Code:@ManagedResource(objectName="TEST:name=HelloWorldMBean", description="HW Management Bean") public class HelloWorld { String name; Properties myProperties; @ManagedAttribute public void setName(String n) { name = n; } @ManagedAttribute public String getName() { return name; } }
My Spring JMX xml file is;
thanks.HTML Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true"></property> </bean> <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="autodetect" value="true"/> <property name="assembler" ref="assembler"/> <property name="namingStrategy" ref="namingStrategy"/> <property name="server" ref="mbeanServer" /> </bean> <bean id="testBean" class="test.HelloWorld"> </bean> <!-- (for Java 5+ annotations-based metadata) --> <bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/> <!-- will pick up the ObjectName from the annotation --> <bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy"> <property name="attributeSource" ref="jmxAttributeSource"/> </bean> <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> <property name="attributeSource" ref="jmxAttributeSource"/> </bean> </beans>


Reply With Quote