diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java index ca76684778..58c6e305ef 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java @@ -54,9 +54,9 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.method.HandlerMethod; +import org.springframework.web.server.ResponseStatusException; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.handler.MatchableHandlerMapping; import org.springframework.web.servlet.handler.RequestMatchResult; @@ -291,7 +291,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin return handleResult(this.operation.invoke(invocationContext), HttpMethod.resolve(request.getMethod())); } catch (InvalidEndpointRequestException ex) { - throw new BadOperationRequestException(ex.getReason()); + throw new InvalidEndpointBadRequestException(ex); } } @@ -404,11 +404,14 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin } - @ResponseStatus(code = HttpStatus.BAD_REQUEST) - private static class BadOperationRequestException extends RuntimeException { + /** + * Nested exception used to wrap a {@link InvalidEndpointRequestException} and provide + * a {@link HttpStatus#BAD_REQUEST} status. + */ + private static class InvalidEndpointBadRequestException extends ResponseStatusException { - BadOperationRequestException(String message) { - super(message); + InvalidEndpointBadRequestException(InvalidEndpointRequestException cause) { + super(HttpStatus.BAD_REQUEST, cause.getReason(), cause); } }