diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java b/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java index 0a808de2970..f1b7febaf2a 100644 --- a/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java +++ b/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java @@ -37,9 +37,6 @@ import org.springframework.util.StringUtils; * Implementation of the JmxAttributeSource interface that * reads JDK 1.5+ annotations and exposes the corresponding attributes. * - *

This is a direct alternative to AttributesJmxAttributeSource, - * which is able to read in source-level attributes via Commons Attributes. - * * @author Rob Harrop * @author Juergen Hoeller * @author Jennifer Hickey @@ -66,7 +63,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource { public ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { org.springframework.jmx.export.annotation.ManagedAttribute ann = - AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedAttribute.class); + AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedAttribute.class); if (ann == null) { return null; } @@ -80,7 +77,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource { public ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException { org.springframework.jmx.export.annotation.ManagedMetric ann = - AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedMetric.class); + AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedMetric.class); if (ann == null) { return null; } @@ -95,12 +92,10 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource { throw new InvalidMetadataException( "The ManagedOperation attribute is not valid for JavaBean properties. Use ManagedAttribute instead."); } - Annotation ann = AnnotationUtils.getAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class); if (ann == null) { return null; } - ManagedOperation op = new ManagedOperation(); AnnotationBeanUtils.copyPropertiesToBean(ann, op); return op; diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/ManagedResource.java b/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/ManagedResource.java index 4b7345c5214..2d693f507a5 100644 --- a/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/ManagedResource.java +++ b/org.springframework.context/src/main/java/org/springframework/jmx/export/annotation/ManagedResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,14 +18,19 @@ package org.springframework.jmx.export.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * JDK 1.5+ class-level annotation that indicates to register - * instances of a class with a JMX server, corresponding to - * the ManagedResource attribute. + * JDK 1.5+ class-level annotation that indicates to register instances of a + * class with a JMX server, corresponding to the ManagedResource attribute. + * + *

Note: This annotation is marked as inherited, allowing for generic + * management-aware base classes. In such a scenario, it is recommended to + * not specify an object name value since this would lead to naming + * collisions in case of multiple subclasses getting registered. * * @author Rob Harrop * @author Juergen Hoeller @@ -34,6 +39,7 @@ import java.lang.annotation.Target; */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) +@Inherited @Documented public @interface ManagedResource { diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java b/org.springframework.context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java index 23d6e048e46..2f496163be1 100644 --- a/org.springframework.context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java +++ b/org.springframework.context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.jmx.export.naming; import java.util.Hashtable; - import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -38,16 +37,14 @@ import org.springframework.util.StringUtils; * *

Uses the {@link JmxAttributeSource} strategy interface, so that * metadata can be read using any supported implementation. Out of the box, - * two strategies are included: - *

+ * {@link org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource} + * introspects a well-defined set of Java 5 annotations that come with Spring. * * @author Rob Harrop * @author Juergen Hoeller * @since 1.2 * @see ObjectNamingStrategy + * @see org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource */ public class MetadataNamingStrategy implements ObjectNamingStrategy, InitializingBean { @@ -125,7 +122,7 @@ public class MetadataNamingStrategy implements ObjectNamingStrategy, Initializin if (domain == null) { domain = ClassUtils.getPackageName(managedClass); } - Hashtable properties = new Hashtable(); + Hashtable properties = new Hashtable(); properties.put("type", ClassUtils.getShortName(managedClass)); properties.put("name", beanKey); return ObjectNameManager.getInstance(domain, properties);