Expose your Own Diagnostics
Your app has more to say: expose it with a custom Actuator endpoint!
🔸 TLDR
▪️ Add Spring Boot Actuator to your project 📦
▪️ Choose which endpoints should be exposed 🌐
▪️ Create a custom endpoint with @Endpoint ⚙️
▪️ Publish data with @ReadOperation 📤
▪️ Protect operational endpoints in production 🔐
🔸 TRUTH
Spring Boot Actuator gives you health checks, metrics, and monitoring endpoints out of the box.
But you are not limited to the default endpoints. 👀
Inspired by Vlad Mihalcea, Java Champion, here is how to expose your own application diagnostics through Actuator.
1️⃣ ADD SPRING BOOT ACTUATOR
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
This dependency enables Spring Boot’s monitoring and management infrastructure.
2️⃣ EXPOSE THE CUSTOM ENDPOINT
management.endpoints.web.exposure.include=health,info,hypersistence-optimizer
Expose only the endpoints you need. Using * is convenient locally, but it can reveal sensitive operational data in production. 🔐
3️⃣ CREATE YOUR CUSTOM ENDPOINT
@Component @Endpoint(id = "hypersistence-optimizer") class OptimizerEndpoint { @ReadOperation List<String> events() { return optimizer.getEvents().stream() .map(Event::getDescription) .toList(); } }
@Endpoint defines the endpoint name, while @ReadOperation exposes data through an HTTP GET request.
The result becomes available at:
GET /actuator/hypersistence-optimizer
The endpoint can return useful diagnostics such as:
▪️ Missing JDBC batching configuration
▪️ Inefficient identifier strategies
▪️ Hibernate dialect mismatches
▪️ Dangerous in-memory pagination
▪️ Query plan cache recommendations
This turns internal technical knowledge into observable operational data. 🔎
🔸 TAKEAWAYS
▪️ Actuator is extensible, not just a collection of predefined endpoints.
▪️ Custom endpoints are useful for diagnostics, maintenance information, feature states, cache details, or application-specific events.
▪️ Keep the endpoint focused on operational information; not business APIs.
▪️ Do not expose every Actuator endpoint publicly.
▪️ Secure sensitive endpoints with Spring Security and restrict their network access.
▪️ For numeric monitoring and dashboards, prefer Micrometer metrics. For readable diagnostics and events, a custom Actuator endpoint can be a great fit.
Observability becomes much more valuable when it reflects the real behavior of your application; not only the JVM. 🚀
#Java #SpringBoot #SpringActuator #SpringFramework #Observability #Monitoring #Micrometer #Hibernate #JPA #SoftwareEngineering #BackendDevelopment
Go further with Java certification:
Java👇
Spring👇
SpringBook👇
JavaBook👇