How to Expose Actuator Endpoints in Spring Boot
To expose actuator endpoints in Spring Boot, add
spring-boot-starter-actuator to your project and configure management.endpoints.web.exposure.include in application.properties or application.yml. By default, only health and info endpoints are exposed; you can specify others like metrics or env explicitly.Syntax
To expose actuator endpoints, you configure the management.endpoints.web.exposure.include property in your application.properties or application.yml file. This property accepts a comma-separated list of endpoint names or * to expose all.
Example properties:
management.endpoints.web.exposure.include=health,info,metricsmanagement.endpoints.web.exposure.include=*(exposes all endpoints)
Also, ensure the actuator dependency is added to your project.
properties
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> application.properties example: management.endpoints.web.exposure.include=health,info,metrics
Example
This example shows a Spring Boot application exposing health, info, and metrics actuator endpoints. The application.properties file configures which endpoints are exposed over HTTP.
java/properties
package com.example.actuatordemo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ActuatorDemoApplication { public static void main(String[] args) { SpringApplication.run(ActuatorDemoApplication.class, args); } } # application.properties management.endpoints.web.exposure.include=health,info,metrics
Output
When running the app, you can access:
- http://localhost:8080/actuator/health
- http://localhost:8080/actuator/info
- http://localhost:8080/actuator/metrics
These endpoints return JSON with health status, app info, and metrics data respectively.
Common Pitfalls
- Not adding the
spring-boot-starter-actuatordependency means no actuator endpoints are available. - By default, only
healthandinfoendpoints are exposed; forgetting to configuremanagement.endpoints.web.exposure.includewill hide others. - Using
management.endpoints.web.exposure.include=*exposes all endpoints, which may be a security risk in production. - Not configuring security properly can block access to actuator endpoints or expose sensitive data.
properties
# Wrong (no exposure configured): management.endpoints.web.exposure.include= # Right (expose health and info): management.endpoints.web.exposure.include=health,info
Quick Reference
| Property | Description | Example Value |
|---|---|---|
| management.endpoints.web.exposure.include | Comma-separated list of endpoints to expose over HTTP | health,info,metrics |
| management.endpoints.web.base-path | Base path for actuator endpoints | /actuator |
| management.endpoint.health.show-details | Controls health endpoint details visibility | always |
| management.endpoints.enabled-by-default | Enable or disable endpoints by default | true |
Key Takeaways
Add spring-boot-starter-actuator dependency to enable actuator endpoints.
Configure management.endpoints.web.exposure.include to specify which endpoints to expose.
By default, only health and info endpoints are exposed; others must be explicitly included.
Use * to expose all endpoints but be cautious about security risks.
Secure actuator endpoints properly to avoid exposing sensitive information.