Mastering Spring Boot Actuator: A Complete Guide to All Native Endpoints
This article provides a thorough walkthrough of Spring Boot Actuator's native endpoints, explaining their purpose, configuration, and usage with practical code examples and screenshots, enabling developers to monitor, diagnose, and manage Spring Boot microservices effectively.
Introduction
In micro‑service architectures built on Spring Cloud or Spring Boot, monitoring is essential. Spring Boot Actuator offers a comprehensive, easy‑to‑use set of endpoints for exposing application health, metrics, configuration, and control functions.
Endpoints Overview
Actuator endpoints (or "Endpoints") allow external tools to interact with a running application. Typical examples include /health for health status and /metrics for JVM and system metrics. Native endpoints are grouped into three categories: application configuration, metric collection, and operational control.
Actuator Base Endpoint
Accessing http://localhost:8080/actuator returns a JSON list of all enabled endpoints. The response can be beautified with a JSON viewer.
auditevents Endpoint
The /auditevents endpoint records authentication and authorization events, but it is only active when an AuditEventRepository bean exists.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>Security configuration is required to expose the events:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin")
.password(bcryptPasswordEncoder().encode("admin"))
.roles("admin");
}
@Bean
public PasswordEncoder bcryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}An in‑memory audit repository is also defined:
@Configuration
public class AuditEventConfig {
@Bean
public InMemoryAuditEventRepository repository(){
return new InMemoryAuditEventRepository();
}
}After restarting, visiting http://localhost:8080/actuator/auditevents shows authentication failures and successes, including timestamps, usernames, event types, and session IDs.
beans Endpoint
/beanslists every bean in the Spring context, showing name, type, scope, and dependencies. It is useful for verifying bean creation.
caches and caches‑cache Endpoints
To demonstrate cache exposure, the project adds spring-boot-starter-cache and enables caching with @EnableCaching. A simple controller returns a map and is annotated with @Cacheable("queryAll").
@RestController
public class CacheController {
@RequestMapping("/queryAll")
@Cacheable(value = "queryAll")
public Map<String, String> queryAll() {
Map<String, String> map = new HashMap<>();
map.put("1", "Tom");
map.put("2", "Steven");
return map;
}
}Before the first request, /actuator/caches shows an empty cache. After calling /queryAll, the cache entry appears, and /actuator/caches/queryAll displays its key, type, and stored data.
health Endpoint
/healthreports the overall status (UP/DOWN) and, when configured, detailed component health. Adding a MySQL datasource and setting management.endpoint.health.show-details=always reveals database, disk, and ping health.
spring:
datasource:
url: jdbc:mysql://xxx:3333/xxx?characterEncoding=utf8&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.DriverWhen the DB credentials are wrong, the health endpoint returns DOWN with an error description.
info Endpoint
/infoexposes custom properties prefixed with info. Adding the following to application.yml:
info:
user:
type: 公众号
name: 程序新视界
wechat: zhuan2quanResults are visible at /actuator/info.
conditions Endpoint
/conditionshelps debug why a particular auto‑configuration class was applied or not, showing matched conditions and messages.
shutdown Endpoint
Enabled via management.endpoint.shutdown.enabled=true, /shutdown accepts a POST request to gracefully stop the application.
curl -X POST "http://localhost:8080/actuator/shutdown"
{
"message": "Shutting down, bye..."
}configprops Endpoint
/configpropslists all beans annotated with @ConfigurationProperties. For the custom InfoProperties class:
@Component
@ConfigurationProperties(prefix = "info")
public class InfoProperties {
private String type;
private String name;
private String wechat;
// getters and setters omitted
}env and env‑toMatch Endpoints
/envreturns all environment properties, while /env/{key} fetches a specific property, e.g., /env/info.user.name.
loggers and loggers‑name Endpoints
/loggerslists all logger configurations; /loggers/{name} shows the effective level for a specific logger, such as the application’s main class.
{
"configuredLevel": null,
"effectiveLevel": "INFO"
}heapdump Endpoint
/heapdumpreturns a JVM heap dump file (binary .hprof) that can be opened with VisualVM for memory analysis.
threaddump Endpoint
/threaddumpprovides a snapshot of all live threads, useful for diagnosing deadlocks or thread‑pool exhaustion.
metrics and metrics‑{name} Endpoints
/metricslists available metric names. Individual metric details are retrieved via /metrics/{name}, e.g., /metrics/jvm.memory.max shows maximum heap size.
{
"names": ["jvm.memory.max", "jvm.threads.states", ...]
} {
"name": "jvm.memory.max",
"description": "The maximum amount of memory in bytes that can be used for memory management",
"baseUnit": "bytes",
"measurements": [{"statistic": "VALUE", "value": 5606211583}],
"availableTags": [{"tag": "area", "values": ["heap", "nonheap"]}, {"tag": "id", "values": ["Compressed Class Space", "PS Survivor Space", "PS Old Gen", "Metaspace", "PS Eden Space", "Code Cache"]}]
}scheduledtasks Endpoint
After enabling scheduling with @EnableScheduling, two tasks are defined—one using a cron expression and another using a fixed delay. /scheduledtasks lists them with their execution patterns.
@Component
public class MyTask {
@Scheduled(cron = "0/10 * * * * *")
public void work() {
System.out.println("I am a cron job.");
}
@Scheduled(fixedDelay = 10000)
public void work1() {
System.out.println("I am a fixedDelay job.");
}
}mappings Endpoint
/mappingsdisplays all URL‑to‑controller mappings, helping developers locate which controller method handles a given request.
Conclusion
The article demonstrates each native Actuator endpoint with concrete code and visual results, showing how Actuator can dramatically simplify runtime inspection, health checking, metric collection, and operational control for Spring Boot microservices.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
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.
