Ok, done.
I've extended MetadataNamingStrategy to replace the domain part of the bean with my own supplied domain name:
Code:
/**
* Extends Spring's MetadataNamingStrategy to allow different names to different instances of the same
* bean when used inside the same container, but on different webapps.
* @author alex.sarco
*
*/
public class DomainMetadataNamingStrategy extends MetadataNamingStrategy {
private String domain;
/**
* Overrides Spring's method to replace the domain name on the objectName with the domain injected here from Spring config.
* Assumes the domain in the bean annotation is 'bean'.
*/
@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
ObjectName objectName = super.getObjectName(managedBean, beanKey);
String newName = objectName.getCanonicalName().replaceFirst("bean", domain);
return ObjectNameManager.getInstance(newName);
}
public void setDomain(String domain) {
this.domain = domain;
}
}
Code:
<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
<bean id="namingStrategy" class="xxx.xxxx.services.jmx.DomainMetadataNamingStrategy">
<property name="attributeSource" ref="jmxAttributeSource"/>
<property name="domain" value="XxxAdmin" />
</bean>
Works like a charm!
Thanks for your help, Mark!