Controlling the ObjectNames for your beans

4.3.9.RELEASE Spring Framework 724 JMX. To control method exposure on a bean-by-bean basis, use the methodMappings property of MethodNameMBeanInfoAssembler to map bean names to lists of method names.

31.4 Controlling the ObjectNames for your beans

Behind the scenes, the MBeanExporter delegates to an implementation of the ObjectNamingStrategy to obtain ObjectName s for each of the beans it is registering. The default implementation, KeyNamingStrategy , will, by default, use the key of the beans Map as the ObjectName . In addition, the KeyNamingStrategy can map the key of the beans Map to an entry in a Properties file or files to resolve the ObjectName . In addition to the KeyNamingStrategy , Spring provides two additional ObjectNamingStrategy implementations: the IdentityNamingStrategy that builds an ObjectName based on the JVM identity of the bean and the MetadataNamingStrategy that uses source level metadata to obtain the ObjectName . Reading ObjectNames from Properties You can configure your own KeyNamingStrategy instance and configure it to read ObjectName s from a Properties instance rather than use bean key. The KeyNamingStrategy will attempt to locate an entry in the Properties with a key corresponding to the bean key. If no entry is found or if the Properties instance is null then the bean key itself is used. The code below shows a sample configuration for the KeyNamingStrategy : beans bean id = exporter class = org.springframework.jmx.export.MBeanExporter property name = beans map entry key = testBean value-ref = testBean map property property name = namingStrategy ref = namingStrategy bean bean id = testBean class = org.springframework.jmx.JmxTestBean property name = name value = TEST property name = age value = 100 bean bean id = namingStrategy class = org.springframework.jmx.export.naming.KeyNamingStrategy property name = mappings props prop key = testBean bean:name=testBean1 prop props property property name = mappingLocations value names1.properties,names2.properties value property bean beans Here an instance of KeyNamingStrategy is configured with a Properties instance that is merged from the Properties instance defined by the mapping property and the properties files located in the paths defined by the mappings property. In this configuration, the testBean bean will be given the ObjectName bean:name=testBean1 since this is the entry in the Properties instance that has a key corresponding to the bean key. If no entry in the Properties instance can be found then the bean key name is used as the ObjectName . 4.3.9.RELEASE Spring Framework 725 Using the MetadataNamingStrategy The MetadataNamingStrategy uses the objectName property of the ManagedResource attribute on each bean to create the ObjectName . The code below shows the configuration for the MetadataNamingStrategy : beans bean id = exporter class = org.springframework.jmx.export.MBeanExporter property name = beans map entry key = testBean value-ref = testBean map property property name = namingStrategy ref = namingStrategy bean bean id = testBean class = org.springframework.jmx.JmxTestBean property name = name value = TEST property name = age value = 100 bean bean id = namingStrategy class = org.springframework.jmx.export.naming.MetadataNamingStrategy property name = attributeSource ref = attributeSource bean bean id = attributeSource class = org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource beans If no objectName has been provided for the ManagedResource attribute, then an ObjectName will be created with the following format:[fully-qualified-package-name]:type=[short- classname],name=[bean-name]. For example, the generated ObjectName for the following bean would be: com.foo:type=MyClass,name=myBean. bean id = myBean class = com.foo.MyClass Configuring annotation based MBean export If you prefer using the annotation based approach to define your management interfaces, then a convenience subclass of MBeanExporter is available: AnnotationMBeanExporter . When defining an instance of this subclass, the namingStrategy , assembler , and attributeSource configuration is no longer needed, since it will always use standard Java annotation-based metadata autodetection is always enabled as well. In fact, rather than defining an MBeanExporter bean, an even simpler syntax is supported by the EnableMBeanExport Configuration annotation. Configuration EnableMBeanExport public class AppConfig { } If you prefer XML based configuration the context:mbean-export element serves the same purpose. context:mbean-export You can provide a reference to a particular MBean server if necessary, and the defaultDomain attribute a property of AnnotationMBeanExporter accepts an alternate value for the generated 4.3.9.RELEASE Spring Framework 726 MBean `ObjectNames’ domains. This would be used in place of the fully qualified package name as described in the previous section on MetadataNamingStrategy . EnableMBeanExportserver=myMBeanServer, defaultDomain=myDomain Configuration ContextConfiguration { } context:mbean-export server = myMBeanServer default-domain = myDomain Note Do not use interface-based AOP proxies in combination with autodetection of JMX annotations in your bean classes. Interface-based proxies hide the target class, which also hides the JMX managed resource annotations. Hence, use target-class proxies in that case: through setting the proxy-target-class flag on aop:config , tx:annotation-driven , etc. Otherwise, your JMX beans might be silently ignored at startup…

31.5 JSR-160 Connectors