How to Use Health Endpoint Actuator in Spring Boot
To use the
/actuator/health endpoint in Spring Boot, add the spring-boot-starter-actuator dependency and enable the health endpoint in your application.properties. Accessing /actuator/health returns the app's health status in JSON format.Syntax
The health endpoint is accessed via the URL /actuator/health. It is part of Spring Boot Actuator, which provides production-ready features. You enable it by adding the actuator starter and configuring properties.
spring-boot-starter-actuator: Adds actuator support.management.endpoints.web.exposure.include=health: Exposes the health endpoint over HTTP./actuator/health: The URL path to check health status.
properties
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}
# application.properties
management.endpoints.web.exposure.include=healthExample
This example shows a minimal Spring Boot application with the health endpoint enabled. When you run the app and visit http://localhost:8080/actuator/health, it returns the health status in JSON.
java
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HealthEndpointApplication { public static void main(String[] args) { SpringApplication.run(HealthEndpointApplication.class, args); } } # application.properties management.endpoints.web.exposure.include=health
Output
{
"status": "UP"
}
Common Pitfalls
Common mistakes include:
- Not adding the
spring-boot-starter-actuatordependency, so the endpoint is missing. - Forgetting to expose the health endpoint via
management.endpoints.web.exposure.include, which keeps it hidden by default. - Accessing the wrong URL path or port.
Always check your configuration and dependencies.
properties
## Wrong: Missing actuator dependency
# No actuator starter added, so health endpoint won't exist
## Wrong: Not exposing health endpoint
# application.properties
management.endpoints.web.exposure.include=info
## Right: Include health endpoint
# application.properties
management.endpoints.web.exposure.include=health,infoQuick Reference
| Property / URL | Description |
|---|---|
| /actuator/health | URL to access the health status JSON |
| spring-boot-starter-actuator | Dependency to add actuator support |
| management.endpoints.web.exposure.include | Property to expose endpoints like health |
| status | Field in JSON showing health status (e.g., UP, DOWN) |
Key Takeaways
Add spring-boot-starter-actuator to enable actuator features including health endpoint.
Expose the health endpoint by setting management.endpoints.web.exposure.include=health in application.properties.
Access the health status at /actuator/health URL to get JSON output of app health.
Without exposing the endpoint, it remains hidden even if actuator is added.
The health endpoint helps monitor app status simply and effectively.