Unlock Spring Boot Actuator: Monitor, Health Checks, and Custom Info
This guide walks through configuring Spring Boot Actuator to expose health, environment, and custom application information, covering dependency setup, endpoint exposure, health grouping, multi‑datasource monitoring, and custom InfoContributor implementation for comprehensive runtime insight.
1. Introduction
In Spring Boot, obtaining runtime status and information is essential for monitoring, debugging, and performance tuning. Spring Boot Actuator provides built‑in endpoints such as /actuator/health and /actuator/info to expose health, OS, Java version, build, environment variables, Git info, and more.
2. Practical Example
2.1 Prepare Environment
Add the actuator starter dependency:
<code><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</code>Configure the management endpoints to expose all paths under a custom base path:
<code>management:
endpoints:
web:
base-path: /ac
exposure:
include: '*'
</code>Now the actuator context path is /ac and all endpoints are visible.
2.2 Application Health
Access /ac/health to see the default health output. To show detailed information, enable it:
<code>management:
endpoint:
health:
show-details: always
</code>Be aware of security implications; restrict access with authentication.
Additional health indicators such as database and Redis can be enabled:
<code>management:
health:
db:
enabled: true
redis:
enabled: true
</code>Grouped health checks can be defined, e.g., a group named pack that includes only db and redis:
<code>management:
endpoint:
health:
group:
pack:
include:
- db
- redis
</code>Access /ac/health/pack to view the group.
2.3 Multi‑DataSource Health
If the project uses a routing data source, Actuator can monitor each source without extra configuration. To ignore routing data sources:
<code>management:
health:
db:
ignore-routing-data-sources: true
</code>3. Application Info
Info endpoints aggregate data from all InfoContributor beans. Enable the desired sections:
<code>management:
info:
env:
enabled: true
java:
enabled: true
build:
enabled: true
git:
enabled: true
os:
enabled: true
</code>Custom info can be added via configuration:
<code>info:
pack:
title: xxxooo Project
version: 1.0.0
author: pack
</code>Or by implementing a custom InfoContributor :
<code>@Component
public class PackInfoContributor implements InfoContributor {
@Override
public void contribute(Builder builder) {
builder.withDetails(Map.of("k1", "v1", "k2", "v2"));
}
}
</code>Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.