Reject multiple @HttpExchange declarations in MVC and WebFlux
This commit updates the RequestMappingHandlerMapping implementations in Spring MVC and Spring WebFlux so that multiple @HttpExchange declarations on the same element are rejected. Closes gh-32049
This commit is contained in:
@@ -360,9 +360,13 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
return createRequestMappingInfo(requestMappings.get(0).annotation, customCondition);
|
||||
}
|
||||
|
||||
HttpExchange httpExchange = AnnotatedElementUtils.findMergedAnnotation(element, HttpExchange.class);
|
||||
if (httpExchange != null) {
|
||||
return createRequestMappingInfo(httpExchange, customCondition);
|
||||
List<AnnotationDescriptor<HttpExchange>> httpExchanges = getAnnotationDescriptors(
|
||||
mergedAnnotations, HttpExchange.class);
|
||||
if (!httpExchanges.isEmpty()) {
|
||||
Assert.state(httpExchanges.size() == 1,
|
||||
() -> "Multiple @HttpExchange annotations found on %s, but only one is allowed: %s"
|
||||
.formatted(element, httpExchanges));
|
||||
return createRequestMappingInfo(httpExchanges.get(0).annotation, customCondition);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user