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-actuatordependency to your
pom.xml:
<code><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</code>/auditevents
Shows audit event information of the current application. Requires an
AuditEventRepositorybean.
/beans
Displays all beans in the Spring application context.
/caches
Lists cache managers and caches. Example response:
<code>{
"cacheManagers": {
"cacheManager": {
"caches": {
"cache_storage": {
"target": "org.springframework.data.redis.cache.DefaultRedisCacheWriter"
}
}
}
}
}
</code>GET
/caches/cache_storagereturns 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:
<code>@Configuration
@ConditionalOnProperty(prefix = "pack", name = "enable", havingValue = "true")
public class CondiationConfig {
}
</code>/configprops
Displays properties bound to configuration beans. Example bean:
<code>@Component
@ConfigurationProperties(prefix = "pack")
public class PackConfigProps {
private String url;
private Integer port;
}
</code>Corresponding YAML:
<code>pack:
url: http://localhost
</code>Only 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.:
<code>@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();
}
}
</code>Enable detail display with:
<code>management:
endpoint:
health:
show-details: always
</code>/httptrace
Shows the last 100 HTTP request/response exchanges. Requires an
HttpTraceRepositorybean, e.g.:
<code>@Configuration
public class HttptraceConfig {
@Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
}
</code>After invoking a web endpoint,
/httptracereturns trace details.
/info
Exposes information defined under the
infoprefix in configuration files.
<code>info:
author: xg
time: 2020-11-30
</code>Access via
/inforeturns 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
@RequestMappingpaths.
/scheduledtasks
Displays scheduled tasks. Example task that runs every 5 seconds:
<code>@Configuration
@EnableScheduling
public class ScheduleConfig {
@Scheduled(cron = "0/5 * * * * ?")
public void task() {
System.out.println("执行任务...");
}
}
</code>/threaddump
Provides a thread dump of the current application.
/shutdown
Shuts down the application (POST). Must be enabled in configuration:
<code>management:
endpoint:
shutdown:
enabled: true
</code>Additional web endpoints
/logfile – returns log file content (requires
logging.file.nameor
logging.file.path).
/heapdump – returns an HPROF heap dump.
/jolokia – exposes JMX beans over HTTP when
jolokia-coreis on the classpath.
/prometheus – exposes metrics for Prometheus when
micrometer-registry-prometheusis present.
Endpoint exposure can be controlled with properties such as
management.endpoints.web.exposure.includeand
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:
<code>@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;
}
}
</code>Access the custom endpoint at
/actuator/custom.
Actuator server customization
Actuator server port and base path can be customized:
<code>management:
server:
port: 8888
endpoints:
web:
basePath: /pack
</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.