Behind the scenes, the MBean Exporter delegates to an implementation of the ObjectNamingStrategy to obtain Objec tNames for each of the beans it is registering. The default implementation, Key Naming Strategy, will, by default, use the key of the beans Map as the ObjectName. In addition, the Key Naming Strategy 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 Key Naming Strategy, Spring provides two additional Object Naming Strategy implementations:
the Identity Naming Strategy that builds an ObjectName based on the JVM identity of the bean and the Metadata NamingStrategy 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 Object Names from a Properties instance rather than use bean key. The Key NamingStrategy 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>
Here an instance of KeyNaming Strategy 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 Object Name 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.
Using the MetadataNamingStrategy
The Metadata Naming Strategy uses the objectName property of the ManagedResource attribute on each bean to create the Object Name. The code below shows the configuration for the Meta data Naming Strategy:
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],
The <context:mbean-export/> element
If you are using at least Java 5, then a convenience subclass of MBean Exporter is available: Annotation MBean Exporter. When defining an instance of this subclass, the naming Strategy, assembler, and attributeSource configuration is no longer needed, since it will always use standard Java annotation-based meta data (autodetection is always enabled as well). In fact, an even simpler syntax is supported by Spring's 'context' namespace.. Rather than defining an MBeanExporter bean, just provide this single element:
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 MBean ObjectNames' domains.
Java-Springs Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Core Java Interview Questions||JSP Interview Questions|
|Java-Springs Interview Questions||Java Servlets Interview Questions|
|JMS(Java Message Service) Interview Questions||Hibernate Interview Questions|
|Java applet Interview Questions||Java Interview Questions|
|Framework7 Interview Questions||Java collections framework Interview Questions|
|Java 8 Interview Questions||Java Programmer Interview Questions|
Introduction To Spring Framework
New Features And Enhancements In Spring 3.0
The Ioc Container
Validation, Data Binding, And Type Conversion
Spring Expression Language (spel)
Aspect Oriented Programming With Spring
Spring Aop Apis
Data Access With Jdbc
Object Relational Mapping (orm) Data Access
Marshalling Xml Using O/x Mappers
Web Mvc Framework
Integrating With Other Web Frameworks
Portlet Mvc Framework
Remoting And Web Services Using Spring
Enterprise Javabeans (ejb) Integration
Jms (java Message Service)
Task Execution And Scheduling
Dynamic Language Support
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.