From 45939720f2b96cf2784e9c34a6ca0d627f8353b7 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 11 Oct 2022 09:37:02 +0200 Subject: [PATCH] Add native support for @ExceptionHandler This commit makes sure that `@ExceptionHandler`-annotated methods can be invoked via reflection in a native image. As most of the handling of the parameter and the return type is shared with our generic RequestMapping handling, the ReflectiveProcessor extends from it. An `@ExceptionHandler`-annotated method can return a `ProblemDetail`. If that's the case, reflection entries are contributed. Closes gh-29297 --- ...ControllerMappingReflectiveProcessor.java} | 57 ++++++++++--------- .../web/bind/annotation/ExceptionHandler.java | 5 +- .../ExceptionHandlerReflectiveProcessor.java | 40 +++++++++++++ .../web/bind/annotation/RequestMapping.java | 2 +- ...ollerMappingReflectiveProcessorTests.java} | 6 +- 5 files changed, 78 insertions(+), 32 deletions(-) rename spring-web/src/main/java/org/springframework/web/bind/annotation/{RequestMappingReflectiveProcessor.java => ControllerMappingReflectiveProcessor.java} (59%) create mode 100644 spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandlerReflectiveProcessor.java rename spring-web/src/test/java/org/springframework/web/bind/annotation/{RequestMappingReflectiveProcessorTests.java => ControllerMappingReflectiveProcessorTests.java} (97%) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMappingReflectiveProcessor.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java similarity index 59% rename from spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMappingReflectiveProcessor.java rename to spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java index d2b03f12c1..878f3af049 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMappingReflectiveProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java @@ -29,11 +29,12 @@ import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.HttpEntity; import org.springframework.lang.Nullable; +import org.springframework.stereotype.Controller; /** - * {@link ReflectiveProcessor} implementation for {@link RequestMapping} - * annotated types. On top of registering reflection hints for invoking - * the annotated method, this implementation handles: + * {@link ReflectiveProcessor} implementation for {@link Controller} and + * controller-specific annotated methods. On top of registering reflection + * hints for invoking the annotated method, this implementation handles: *