Replace manual health endpoint with Spring Boot Actuator
Remove the hand-rolled HealthController and use spring-boot-starter-actuator instead. Only the health endpoint is exposed, with no detail leakage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,11 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package de.fete.adapter.in.web;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/** REST endpoint for health checks. */
|
|
||||||
@RestController
|
|
||||||
public class HealthController {
|
|
||||||
|
|
||||||
/** Returns a simple health status. */
|
|
||||||
@GetMapping("/health")
|
|
||||||
public Map<String, String> health() {
|
|
||||||
return Map.of("status", "ok");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +1,4 @@
|
|||||||
spring.application.name=fete
|
spring.application.name=fete
|
||||||
|
|
||||||
|
management.endpoints.web.exposure.include=health
|
||||||
|
management.endpoint.health.show-details=never
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ class FeteApplicationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void healthEndpointReturns200() throws Exception {
|
void healthEndpointReturns200() throws Exception {
|
||||||
mockMvc.perform(get("/health"))
|
mockMvc.perform(get("/actuator/health"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.status").value("ok"));
|
.andExpect(jsonPath("$.status").value("UP"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user