Unlock Spring Boot Actuator: All Endpoints, Configurations, and Code Samples
Spring Boot Actuator provides extensive monitoring and management features via HTTP and JMX; this guide shows how to enable it, lists each endpoint such as /auditevents, /beans, /caches, /conditions, /env, /health, and demonstrates configuration, custom endpoints, and code examples for full utilization.
Spring Boot provides many additional features for monitoring and managing applications, accessible via HTTP or JMX.
Enable it by adding the spring-boot-starter-actuator dependency to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>/auditevents
Shows audit event information of the current application. Requires an AuditEventRepository bean.
/beans
Displays all beans in the Spring application context.
/caches
Lists cache managers and caches. Example response:
{
"cacheManagers": {
"cacheManager": {
"caches": {
"cache_storage": {
"target": "org.springframework.data.redis.cache.DefaultRedisCacheWriter"
}
}
}
}
}GET /caches/cache_storage returns details of a specific cache manager; DELETE clears its contents.
/conditions
Shows which configuration classes and auto‑configuration classes were applied and why some were not. Example:
@Configuration
@ConditionalOnProperty(prefix = "pack", name = "enable", havingValue = "true")
public class CondiationConfig {
}/configprops
Displays properties bound to configuration beans. Example bean:
@Component
@ConfigurationProperties(prefix = "pack")
public class PackConfigProps {
private String url;
private Integer port;
}Corresponding YAML:
pack:
url: http://localhostOnly the configured properties appear in the endpoint output.
/env
Exposes all environment variables; specific variables can be queried via /env/{name}.
/health
Shows application health status. Custom health indicators can add details, e.g.:
@Component
public class CustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
Map<String, Object> details = new HashMap<>();
details.put("code", "0");
details.put("message", "成功");
return Health.up().withDetails(details).build();
}
}Enable detail display with:
management:
endpoint:
health:
show-details: always/httptrace
Shows the last 100 HTTP request/response exchanges. Requires an HttpTraceRepository bean, e.g.:
@Configuration
public class HttptraceConfig {
@Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
}After invoking a web endpoint, /httptrace returns trace details.
/info
Exposes information defined under the info prefix in configuration files.
info:
author: xg
time: 2020-11-30Access via /info returns the JSON above.
/loggers
View or modify logger configuration.
/metrics
Lists all available metrics; individual metric values can be retrieved, e.g. /metrics/jvm.memory.max.
/mappings
Shows all @RequestMapping paths.
/scheduledtasks
Displays scheduled tasks. Example task that runs every 5 seconds:
@Configuration
@EnableScheduling
public class ScheduleConfig {
@Scheduled(cron = "0/5 * * * * ?")
public void task() {
System.out.println("执行任务...");
}
}/threaddump
Provides a thread dump of the current application.
/shutdown
Shuts down the application (POST). Must be enabled in configuration:
management:
endpoint:
shutdown:
enabled: trueAdditional web endpoints
/logfile – returns log file content (requires logging.file.name or logging.file.path).
/heapdump – returns an HPROF heap dump.
/jolokia – exposes JMX beans over HTTP when jolokia-core is on the classpath.
/prometheus – exposes metrics for Prometheus when micrometer-registry-prometheus is present.
Endpoint exposure can be controlled with properties such as management.endpoints.web.exposure.include and management.endpoints.web.exposure.exclude. Use “*” to enable all endpoints.
Custom endpoints
Custom endpoints can be created with @Endpoint (supports JMX and HTTP) or @WebEndpoint (HTTP only). Example:
@Endpoint(id = "custom")
@Component
public class CustomEndpoint {
@ReadOperation
public Map<String, Object> info() {
Map<String, Object> res = new HashMap<>();
res.put("code", 0);
return res;
}
}Access the custom endpoint at /actuator/custom.
Actuator server customization
Actuator server port and base path can be customized:
management:
server:
port: 8888
endpoints:
web:
basePath: /packSigned-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.
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.
