mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-28 01:59:04 +00:00
Cache ResponseBody annotation presence per controller class
See gh-36311
This commit is contained in:
+7
-2
@@ -19,6 +19,8 @@ package org.springframework.web.reactive.result.method.annotation;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -53,6 +55,9 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
*/
|
||||
public class ResponseBodyResultHandler extends AbstractMessageWriterResultHandler implements HandlerResultHandler {
|
||||
|
||||
private final Map<Class<?>, Boolean> responseBodyControllerCache = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Basic constructor with a default {@link ReactiveAdapterRegistry}.
|
||||
* @param writers the writers for serializing to the response body
|
||||
@@ -93,8 +98,8 @@ public class ResponseBodyResultHandler extends AbstractMessageWriterResultHandle
|
||||
@Override
|
||||
public boolean supports(HandlerResult result) {
|
||||
MethodParameter returnType = result.getReturnTypeSource();
|
||||
Class<?> containingClass = returnType.getContainingClass();
|
||||
return (AnnotatedElementUtils.hasAnnotation(containingClass, ResponseBody.class) ||
|
||||
return (this.responseBodyControllerCache.computeIfAbsent(returnType.getContainingClass(),
|
||||
clazz -> AnnotatedElementUtils.hasAnnotation(clazz, ResponseBody.class)) ||
|
||||
returnType.hasMethodAnnotation(ResponseBody.class));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user