Polishing

This commit is contained in:
Sam Brannen
2024-01-18 15:11:53 +01:00
parent 6b905049eb
commit c5c77b93fe
3 changed files with 54 additions and 44 deletions

View File

@@ -189,16 +189,13 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
MergedAnnotations mergedAnnotations = MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY,
RepeatableContainers.none());
List<AnnotationDescriptor<RequestMapping>> requestMappings = mergedAnnotations.stream(RequestMapping.class)
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
.map(AnnotationDescriptor::new)
.distinct()
.toList();
List<AnnotationDescriptor<RequestMapping>> requestMappings = getAnnotationDescriptors(
mergedAnnotations, RequestMapping.class);
if (!requestMappings.isEmpty()) {
if (requestMappings.size() > 1 && logger.isWarnEnabled()) {
logger.warn("Multiple @RequestMapping annotations found on %s, but only the first will be used: %s"
.formatted(element, requestMappings));
.formatted(element, requestMappings));
}
return createRequestMappingInfo(requestMappings.get(0).annotation, customCondition);
}
@@ -430,6 +427,16 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
}
}
private static <A extends Annotation> List<AnnotationDescriptor<A>> getAnnotationDescriptors(
MergedAnnotations mergedAnnotations, Class<A> annotationType) {
return mergedAnnotations.stream(annotationType)
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
.map(AnnotationDescriptor::new)
.distinct()
.toList();
}
private static class AnnotationDescriptor<A extends Annotation> {
private final A annotation;