0
0
Spring Bootframework~10 mins

Custom actuator endpoints in Spring Boot - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Custom actuator endpoints
Start Spring Boot App
Define Custom Endpoint Class
Annotate with @Endpoint
Add @ReadOperation or @WriteOperation
App Runs and Registers Endpoint
Call /actuator/custom
Execute Method and Return Data
Client Receives Response
The app starts, registers a custom actuator endpoint class with annotated methods, then serves data when the endpoint URL is called.
Execution Sample
Spring Boot
import org.springframework.boot.actuate.endpoint.annotation.*;

@Endpoint(id = "custom")
public class CustomEndpoint {
  @ReadOperation
  public String info() { return "Hello from custom endpoint"; }
}
Defines a custom actuator endpoint named 'custom' that returns a simple string when accessed.
Execution Table
StepActionAnnotation UsedResultEndpoint URL
1Spring Boot startsN/AApp context initializedN/A
2CustomEndpoint class loaded@Endpoint(id="custom")Endpoint registeredN/A
3info() method detected@ReadOperationMethod ready to serve GET requestsN/A
4HTTP GET /actuator/custom calledN/Ainfo() method invoked/actuator/custom
5info() returns stringN/A"Hello from custom endpoint"/actuator/custom
6Response sent to clientN/AClient receives "Hello from custom endpoint"/actuator/custom
💡 Execution stops after response is sent to client for the custom actuator endpoint.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 5Final
App ContextEmptyInitialized with CustomEndpoint beanCustomEndpoint methods registeredN/ARunning with endpoint ready
CustomEndpoint.info()Not calledRegisteredReady"Hello from custom endpoint"Returned response
Key Moments - 3 Insights
Why do we need @Endpoint and @ReadOperation annotations?
The @Endpoint annotation marks the class as a custom actuator endpoint (see Step 2). The @ReadOperation marks the method to handle GET requests (see Step 3). Without these, Spring Boot won't register or expose the endpoint.
What URL do I use to call my custom endpoint?
The URL is /actuator/{id} where id is from @Endpoint(id). Here, it is /actuator/custom as shown in Steps 4-6.
Can the method return other data types?
Yes, methods can return any serializable data like String, Map, or POJOs. Spring Boot converts it to JSON automatically (Step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what annotation registers the class as an actuator endpoint?
A@ReadOperation
B@Endpoint
C@WriteOperation
D@Component
💡 Hint
Check Step 2 in the execution table where the class is registered.
At which step does the custom endpoint method get called?
AStep 4
BStep 2
CStep 3
DStep 6
💡 Hint
Look for the HTTP GET request triggering the method invocation.
If you change @Endpoint(id = "custom") to @Endpoint(id = "info"), what changes?
AThe app will not start
BThe method name must change to info()
CThe endpoint URL changes to /actuator/info
DThe response string changes automatically
💡 Hint
Refer to the URL column in the execution table and how id affects it.
Concept Snapshot
Custom actuator endpoints let you add your own monitoring URLs.
Use @Endpoint(id = "name") on a class.
Use @ReadOperation for GET methods.
Spring Boot exposes it at /actuator/name.
Return any data; it converts to JSON.
Useful for custom health or info checks.
Full Transcript
This visual trace shows how to create a custom actuator endpoint in Spring Boot. First, the app starts and loads the CustomEndpoint class annotated with @Endpoint. This registers the endpoint with Spring Boot. Then, the method annotated with @ReadOperation is detected and prepared to handle GET requests. When a client calls /actuator/custom, the info() method runs and returns a string. The response is sent back to the client. Variables like the app context and method state change from uninitialized to ready and then to returned response. Key points include the importance of annotations to register and expose the endpoint, the URL pattern based on the id, and the flexibility of return types. The quiz tests understanding of annotations, method invocation step, and URL naming.