Browse Source

Rely on standard @Repeatable support in AnnotationJmxAttributeSource

This commit removes the use of RepeatableContainers.of() in
AnnotationJmxAttributeSource since that is unnecessary when using the
MergedAnnotations API with @⁠Repeatable annotations such as
@⁠ManagedOperationParameter and @⁠ManagedNotification.

Closes gh-34606
pull/34614/head
Sam Brannen 9 months ago
parent
commit
37a135447c
  1. 15
      spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java

15
spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java

@ -41,7 +41,6 @@ import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotationPredicates; import org.springframework.core.annotation.MergedAnnotationPredicates;
import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.core.annotation.RepeatableContainers;
import org.springframework.jmx.export.metadata.InvalidMetadataException; import org.springframework.jmx.export.metadata.InvalidMetadataException;
import org.springframework.jmx.export.metadata.JmxAttributeSource; import org.springframework.jmx.export.metadata.JmxAttributeSource;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -152,9 +151,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
public org.springframework.jmx.export.metadata.@Nullable ManagedOperationParameter[] getManagedOperationParameters( public org.springframework.jmx.export.metadata.@Nullable ManagedOperationParameter[] getManagedOperationParameters(
Method method) throws InvalidMetadataException { Method method) throws InvalidMetadataException {
List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations( List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations(method, ManagedOperationParameter.class);
method, ManagedOperationParameter.class, ManagedOperationParameters.class);
return copyPropertiesToBeanArray(anns, org.springframework.jmx.export.metadata.ManagedOperationParameter.class); return copyPropertiesToBeanArray(anns, org.springframework.jmx.export.metadata.ManagedOperationParameter.class);
} }
@ -162,19 +159,15 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
public org.springframework.jmx.export.metadata.@Nullable ManagedNotification[] getManagedNotifications(Class<?> clazz) public org.springframework.jmx.export.metadata.@Nullable ManagedNotification[] getManagedNotifications(Class<?> clazz)
throws InvalidMetadataException { throws InvalidMetadataException {
List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations( List<MergedAnnotation<? extends Annotation>> anns = getRepeatableAnnotations(clazz, ManagedNotification.class);
clazz, ManagedNotification.class, ManagedNotifications.class);
return copyPropertiesToBeanArray(anns, org.springframework.jmx.export.metadata.ManagedNotification.class); return copyPropertiesToBeanArray(anns, org.springframework.jmx.export.metadata.ManagedNotification.class);
} }
private static List<MergedAnnotation<? extends Annotation>> getRepeatableAnnotations( private static List<MergedAnnotation<? extends Annotation>> getRepeatableAnnotations(
AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType) {
Class<? extends Annotation> containerAnnotationType) {
return MergedAnnotations.from(annotatedElement, SearchStrategy.TYPE_HIERARCHY, return MergedAnnotations.from(annotatedElement, SearchStrategy.TYPE_HIERARCHY)
RepeatableContainers.of(annotationType, containerAnnotationType))
.stream(annotationType) .stream(annotationType)
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
.map(MergedAnnotation::withNonMergedAttributes) .map(MergedAnnotation::withNonMergedAttributes)

Loading…
Cancel
Save