Bird
Raised Fist0
Spring Bootframework~20 mins

Custom actuator endpoints in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Custom Actuator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this custom actuator endpoint?
Given the following Spring Boot custom actuator endpoint code, what will be the JSON output when accessing /actuator/customStatus?
Spring Boot
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

@Component
@Endpoint(id = "customStatus")
public class CustomStatusEndpoint {

    @ReadOperation
    public Status status() {
        return new Status("UP", "All systems operational");
    }

    public record Status(String state, String message) {}
}
A{"status":"UP","info":"All systems operational"}
B{"state":"UP","message":"All systems operational"}
C{"state":"DOWN","message":"All systems operational"}
D{"state":"UP"}
Attempts:
2 left
💡 Hint
Look at the record fields and the returned object structure.
📝 Syntax
intermediate
2:00remaining
Which option correctly defines a write operation in a custom actuator endpoint?
You want to create a custom actuator endpoint with a write operation that accepts a String parameter. Which code snippet correctly defines the write operation method?
Spring Boot
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;

// Method to define:
A
@WriteOperation
public String updateStatus(@Selector String newStatus) { return "Updated to " + newStatus; }
B
@WriteOperation
public String updateStatus(String newStatus) { return "Updated to " + newStatus; }
C
@WriteOperation
public String updateStatus() { return "Updated"; }
D
@WriteOperation
public void updateStatus(String newStatus) { System.out.println(newStatus); }
Attempts:
2 left
💡 Hint
Write operations with parameters require @Selector annotation for each parameter.
🔧 Debug
advanced
2:00remaining
Why does this custom actuator endpoint fail to register?
Consider this custom endpoint class: @Component @Endpoint(id = "failEndpoint") public class FailEndpoint { public String status() { return "OK"; } } Why does Spring Boot fail to register this endpoint?
AThe class must extend AbstractEndpoint to be recognized.
BThe endpoint id 'failEndpoint' is invalid because it contains uppercase letters.
CThe method 'status' lacks a @ReadOperation annotation.
DThe class is missing @RestController annotation.
Attempts:
2 left
💡 Hint
Check if the method is properly annotated to expose it as an endpoint operation.
❓ state_output
advanced
2:00remaining
What is the state of the custom endpoint after calling the write operation twice?
Given this custom endpoint: @Component @Endpoint(id = "counter") public class CounterEndpoint { private int count = 0; @ReadOperation public int getCount() { return count; } @WriteOperation public void increment() { count++; } } If you call the write operation /actuator/counter twice, then call the read operation, what is the returned count?
A2
B1
C0
DCannot determine because endpoints are stateless
Attempts:
2 left
💡 Hint
Consider the instance variable and how many times increment is called.
🧠 Conceptual
expert
2:00remaining
Which statement about custom actuator endpoints is true?
Select the correct statement about custom actuator endpoints in Spring Boot.
ACustom actuator endpoints require extending AbstractEndpoint class to function.
BCustom actuator endpoints must be registered manually in application.properties to be exposed.
CCustom actuator endpoints cannot accept parameters in their operations.
DCustom actuator endpoints can expose multiple operations annotated with @ReadOperation, @WriteOperation, and @DeleteOperation within the same class.
Attempts:
2 left
💡 Hint
Think about the flexibility of operation types in one endpoint class.

Practice

(1/5)
1. What annotation is used to define a custom actuator endpoint in Spring Boot?
easy
A. @Endpoint
B. @Controller
C. @Service
D. @RestController

Solution

  1. Step 1: Understand the purpose of custom actuator endpoints

    Custom actuator endpoints allow you to add your own monitoring or info checks in Spring Boot.
  2. Step 2: Identify the correct annotation for defining custom endpoints

    The @Endpoint annotation is specifically designed to mark a class as a custom actuator endpoint.
  3. Final Answer:

    @Endpoint -> Option A
  4. Quick Check:

    Custom actuator endpoint = @Endpoint [OK]
Hint: Custom actuator endpoints always use @Endpoint annotation [OK]
Common Mistakes:
  • Confusing @Endpoint with @Controller
  • Using @Service instead of @Endpoint
  • Using @RestController which is for REST APIs
2. Which annotation should you use on a method inside a custom actuator endpoint to expose a read-only operation?
easy
A. @WriteOperation
B. @ReadOperation
C. @GetMapping
D. @PostMapping

Solution

  1. Step 1: Recall method annotations for custom actuator endpoints

    Custom actuator endpoints use specific annotations to define operations: read or write.
  2. Step 2: Match read-only operation annotation

    The @ReadOperation annotation marks a method as a read-only operation accessible via HTTP GET.
  3. Final Answer:

    @ReadOperation -> Option B
  4. Quick Check:

    Read-only method = @ReadOperation [OK]
Hint: Use @ReadOperation for read-only endpoint methods [OK]
Common Mistakes:
  • Using @WriteOperation for read methods
  • Confusing @GetMapping with actuator annotations
  • Using @PostMapping which is for REST controllers
3. Given this custom endpoint class, what will be the HTTP response body when accessing the endpoint?
@Endpoint(id = "status")
public class StatusEndpoint {
  @ReadOperation
  public String getStatus() {
    return "UP";
  }
}
medium
A. "DOWN"
B. 404 Not Found
C. "UP"
D. 500 Internal Server Error

Solution

  1. Step 1: Analyze the custom endpoint class

    The class is annotated with @Endpoint(id = "status") and has a method with @ReadOperation returning "UP".
  2. Step 2: Understand the HTTP response from the read operation

    Accessing the actuator endpoint with id "status" triggers the getStatus() method, returning the string "UP" as the response body.
  3. Final Answer:

    "UP" -> Option C
  4. Quick Check:

    Read operation returns "UP" [OK]
Hint: ReadOperation returns method result as HTTP response body [OK]
Common Mistakes:
  • Expecting 404 if endpoint is defined correctly
  • Confusing return value with HTTP status code
  • Assuming method returns JSON object instead of string
4. Identify the error in this custom actuator endpoint code:
@Endpoint(id = "metrics")
public class MetricsEndpoint {
  @ReadOperation
  public String metrics() {
    return 12345;
  }
}
medium
A. The @ReadOperation annotation is missing
B. The method name must be getMetrics
C. The @Endpoint annotation must be on a method, not class
D. The method declares String return type but returns an int

Solution

  1. Step 1: Check method return type consistency

    The method metrics() returns an integer literal 12345 but declares return type String, causing a type mismatch.
  2. Step 2: Verify annotations and method naming

    The @ReadOperation annotation is present, and @Endpoint is correctly on the class. Method name can be arbitrary.
  3. Final Answer:

    The method declares String return type but returns an int -> Option D
  4. Quick Check:

    Return type mismatch causes error [OK]
Hint: Method return type must match declared type [OK]
Common Mistakes:
  • Thinking @Endpoint goes on methods
  • Assuming method name must follow getter pattern
  • Ignoring type mismatch errors
5. You want to create a custom actuator endpoint that accepts a POST request to update a configuration value. Which combination of annotations and method signature is correct? A)
@Endpoint(id = "config")
public class ConfigEndpoint {
  @WriteOperation
  public String updateConfig(String key, String value) {
    // update logic
    return "Updated";
  }
}
B)
@Endpoint(id = "config")
public class ConfigEndpoint {
  @ReadOperation
  public void updateConfig(String key, String value) {
    // update logic
  }
}
C)
@Endpoint(id = "config")
public class ConfigEndpoint {
  @WriteOperation
  public void updateConfig() {
    // update logic
  }
}
D)
@Endpoint(id = "config")
public class ConfigEndpoint {
  @WriteOperation
  public String updateConfig() {
    // update logic
    return "Updated";
  }
}
hard
A. Option A is correct because @WriteOperation supports parameters and returns a response
B. Option B is correct because @ReadOperation can update values
C. Option C is correct because @WriteOperation methods cannot have parameters
D. Option D is correct because @WriteOperation methods should not have parameters

Solution

  1. Step 1: Understand @WriteOperation usage

    @WriteOperation marks methods that handle write operations, typically POST, and can accept parameters for input.
  2. Step 2: Analyze method signatures and annotations

    The correct combination uses @WriteOperation with String key and String value parameters and returns a String response, which is valid for POST updates. Using @ReadOperation is wrong for update operations. The other snippets lack parameters needed to receive key and value.
  3. Final Answer:

    Option A is correct because @WriteOperation supports parameters and returns a response -> Option A
  4. Quick Check:

    @WriteOperation with parameters for POST updates [OK]
Hint: Use @WriteOperation with parameters for POST updates [OK]
Common Mistakes:
  • Using @ReadOperation for write/update methods
  • Omitting parameters needed for update
  • Assuming @WriteOperation methods cannot return values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard