Repository navigation
Closed
Description
Gary Russell opened SPR-8244 and commented
MBeanExporters in Spring Integration and Spring Batch provide an attribute to specify additional components of the object name. It would be nice if core could do the same. When using @ManagedResource, one has to use a static name; this causes issues if multiple instances are deployed in the same JVM.
Currently using this as a work-around
public class EnhancedMetadataNamingStrategy extends MetadataNamingStrategy {
private String staticNameParts = "";
public EnhancedMetadataNamingStrategy(
AnnotationJmxAttributeSource annotationSource) {
super(annotationSource);
}
@Override
public ObjectName getObjectName(Object managedBean, String beanKey)
throws MalformedObjectNameException {
ObjectName objectName = super.getObjectName(managedBean, beanKey);
if (this.staticNameParts.length() == 0) {
return objectName;
}
return new ObjectName(objectName.getCanonicalName() + this.staticNameParts);
}
/**
* Static properties that will be added to all object names.
*
* @param objectNameStaticProperties the objectNameStaticProperties to set
*/
public void setObjectNameStaticProperties(Map<String, String> objectNameStaticProperties) {
StringBuilder builder = new StringBuilder();
for (String key : objectNameStaticProperties.keySet()) {
builder.append("," + key + "=" + objectNameStaticProperties.get(key));
}
this.staticNameParts = builder.toString();
}
}
<bean class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter">
<property name="defaultDomain" value="spring.application"/>
<property name="namingStrategy">
<bean class="org.springframework.integration.cluster.health.EnhancedMetadataNamingStrategy">
<constructor-arg>
<bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
</constructor-arg>
<property name="objectNameStaticProperties">
<map>
<entry key="application" value="${application.id}"/>
</map>
</property>
</bean>
</property>
</bean>
See also INT-1817 (SI did not expose the map via the namespace).
Affects: 3.0.5
Sub-tasks:
- Eliminate package cycle introduced by SPR-8244 [SPR-10021] #14655 Eliminate package cycle introduced by SPR-8244
Referenced from: commits 0e02007
0 votes, 10 watchers
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancement
Activity
spring-projects-issues commentedon Jul 18, 2012
Gary Russell commented
Correction to config...
spring-projects-issues commentedon Oct 19, 2012
Gary Russell commented
As discussed today, another possibility - perhaps even better - would be to allow a SpEL expression in the @ ManagedResource objectName attribute so the object name can be easily externalized.
spring-projects-issues commentedon Oct 19, 2012
Gary Russell commented
The use of SpEL could perhaps also be made available in other selected Annotations (e.g.
@RequestMapping).spring-projects-issues commentedon Oct 30, 2012
Juergen Hoeller commented
I've finally addressed this for 3.2 RC1, through support for regular Spring placeholders (as parsed by PropertyPlaceholderConfigurer) in all applicable ManagedResource annotation attributes.
Juergen