diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java index e382ed07c2..76dd55d845 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java @@ -361,8 +361,7 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi return new ResponseEntity<>(response, HttpStatus.OK); } WebEndpointResponse webEndpointResponse = (WebEndpointResponse) response; - return new ResponseEntity<>(webEndpointResponse.getBody(), - HttpStatus.valueOf(webEndpointResponse.getStatus())); + return ResponseEntity.status(webEndpointResponse.getStatus()).body(webEndpointResponse.getBody()); } @Override 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 35597ea1ff..1c30155fb8 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 @@ -367,7 +367,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin return result; } WebEndpointResponse response = (WebEndpointResponse) result; - return new ResponseEntity(response.getBody(), HttpStatus.valueOf(response.getStatus())); + return ResponseEntity.status(response.getStatus()).body(response.getBody()); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java index 53c7d1da8a..409f14b7c3 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java @@ -380,6 +380,12 @@ public abstract class AbstractWebEndpointIntegrationTests context.register(CustomResponseStatusEndpointConfiguration.class), + (client) -> client.get().uri("/customstatus").exchange().expectStatus().isEqualTo(234)); + } + protected abstract int getPort(T context); protected void validateErrorBody(WebTestClient.BodyContentSpec body, HttpStatus status, String path, @@ -624,6 +630,17 @@ public abstract class AbstractWebEndpointIntegrationTests read() { + return new WebEndpointResponse<>("Custom status", 234); + } + + } + interface EndpointDelegate { void write();