Bird
Raised Fist0
Spring Bootframework~20 mins

Health endpoint customization in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Health Endpoint Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of the custom health indicator?
Given this Spring Boot custom health indicator code, what will the /actuator/health endpoint show when the application is running?
Spring Boot
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
public class CustomHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        int errorCode = check(); // perform some specific health check
        if (errorCode != 0) {
            return Health.down().withDetail("Error Code", errorCode).build();
        }
        return Health.up().withDetail("Custom Info", "All systems go").build();
    }

    private int check() {
        return 0; // no error
    }
}
A{"status":"UP","details":{"Custom Info":"All systems go"}}
B{"status":"UP"}
C{"status":"DOWN","details":{"Error Code":0}}
D{"status":"DOWN","details":{"Custom Info":"All systems go"}}
Attempts:
2 left
💡 Hint
Look at the check() method return value and how it affects the health status.
📝 Syntax
intermediate
1:30remaining
Which option correctly disables the default health endpoint?
You want to disable the default /actuator/health endpoint in Spring Boot. Which configuration property and value correctly achieves this?
Amanagement.endpoints.health.enabled=false
Bmanagement.health.enabled=false
Cmanagement.endpoint.health.enabled=false
Dmanagement.endpoint.healths.enabled=false
Attempts:
2 left
💡 Hint
Check the exact property name for enabling or disabling endpoints in Spring Boot actuator.
🔧 Debug
advanced
2:30remaining
Why does the custom health indicator not appear in /actuator/health?
You created a custom HealthIndicator bean but it does not show in the /actuator/health response. What is the most likely cause?
Spring Boot
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
public class MyHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        return Health.up().withDetail("status", "ok").build();
    }
}
AThe application is missing spring-boot-starter-actuator dependency.
BThe management.endpoint.health.show-details property is set to 'never'.
CThe custom HealthIndicator class does not implement HealthIndicator interface.
DThe custom HealthIndicator class is missing @Component annotation.
Attempts:
2 left
💡 Hint
Check the actuator configuration for health details visibility.
❓ state_output
advanced
2:00remaining
What is the health status after simulating a failure?
Consider this custom health indicator that simulates a failure when a flag is true. What will the /actuator/health endpoint show if simulateFailure is true?
Spring Boot
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
public class SimulatedHealthIndicator implements HealthIndicator {
    private boolean simulateFailure = true;

    @Override
    public Health health() {
        if (simulateFailure) {
            return Health.down().withDetail("Failure", "Simulated failure").build();
        }
        return Health.up().build();
    }
}
A{"status":"UNKNOWN"}
B{"status":"UP"}
C{"status":"DOWN"}
D{"status":"DOWN","details":{"Failure":"Simulated failure"}}
Attempts:
2 left
💡 Hint
Look at the simulateFailure flag and how it affects the health status.
🧠 Conceptual
expert
2:30remaining
Which statement about health endpoint customization is true?
Select the correct statement about customizing the Spring Boot health endpoint.
AHealthIndicator beans are aggregated; the health endpoint combines all indicators into one response.
BDisabling the health endpoint requires removing the spring-boot-starter-actuator dependency.
CYou must extend AbstractHealthIndicator to create a custom health indicator; implementing HealthIndicator is not enough.
DCustom HealthIndicator beans automatically override the default health checks and replace them entirely.
Attempts:
2 left
💡 Hint
Think about how Spring Boot combines multiple health indicators.

Practice

(1/5)
1. What is the main purpose of customizing the health endpoint in Spring Boot?
easy
A. To automatically restart the application on failure
B. To change the port number of the application
C. To add specific checks that show detailed app status
D. To disable all health checks

Solution

  1. Step 1: Understand the health endpoint role

    The health endpoint shows the app's status and can be extended to include custom checks.
  2. Step 2: Identify customization purpose

    Customizing allows adding specific checks to provide detailed status beyond default info.
  3. Final Answer:

    To add specific checks that show detailed app status -> Option C
  4. Quick Check:

    Health endpoint customization = detailed app status [OK]
Hint: Health endpoint customization means adding detailed status checks [OK]
Common Mistakes:
  • Thinking it changes app port
  • Assuming it disables health checks
  • Believing it restarts app automatically
2. Which interface must you implement to create a custom health check in Spring Boot?
easy
A. HealthIndicator
B. HealthCheck
C. HealthService
D. HealthStatus

Solution

  1. Step 1: Recall Spring Boot health customization

    Custom health checks require implementing a specific interface.
  2. Step 2: Identify correct interface

    The interface to implement is HealthIndicator, which requires overriding health().
  3. Final Answer:

    HealthIndicator -> Option A
  4. Quick Check:

    Custom health check interface = HealthIndicator [OK]
Hint: Custom health checks need HealthIndicator interface [OK]
Common Mistakes:
  • Using HealthCheck instead of HealthIndicator
  • Confusing with HealthService or HealthStatus
  • Not overriding health() method
3. Given this custom health indicator code, what will the health endpoint show?
public class MyHealth implements HealthIndicator {
  @Override
  public Health health() {
    return Health.up().withDetail("db", "reachable").build();
  }
}
medium
A. {"status":"UP","details":{"db":"reachable"}}
B. {"status":"DOWN","details":{"db":"reachable"}}
C. {"status":"UP"}
D. {"status":"DOWN"}

Solution

  1. Step 1: Analyze health() method return

    The method returns Health.up() with a detail key "db" set to "reachable".
  2. Step 2: Understand output format

    The health endpoint shows status "UP" and includes the details map with "db":"reachable".
  3. Final Answer:

    {"status":"UP","details":{"db":"reachable"}} -> Option A
  4. Quick Check:

    Health.up() with details = status UP plus details [OK]
Hint: Health.up() withDetail adds details and sets status UP [OK]
Common Mistakes:
  • Confusing UP with DOWN status
  • Ignoring details in output
  • Assuming default status without details
4. Identify the error in this custom health indicator code:
public class CustomHealth implements HealthIndicator {
  public Health health() {
    return Health.down().withDetails("error", "Database unreachable").build();
  }
}
medium
A. Method should be annotated with @Override
B. withDetails() method does not exist, should be withDetail()
C. Method name should be checkHealth() instead of health()
D. Health.down() cannot be used in custom indicators

Solution

  1. Step 1: Check method signature and annotations

    The method correctly named health() matches interface; @Override annotation is optional but recommended.
  2. Step 2: Verify method calls on Health builder

    The method withDetails() does not exist; correct method is withDetail() for adding one detail.
  3. Final Answer:

    withDetails() method does not exist, should be withDetail() -> Option B
  4. Quick Check:

    Use withDetail() to add single detail [OK]
Hint: Use withDetail() not withDetails() to add details [OK]
Common Mistakes:
  • Missing @Override annotation (not error but best practice)
  • Wrong method name instead of health()
  • Thinking Health.down() is invalid
5. You want to customize the health endpoint to show "UP" only if both database and cache are reachable. Which approach correctly implements this logic?
hard
A. Use two separate HealthIndicator classes without combining results
B. Return Health.up() always and add details for database and cache status
C. Return Health.down() always and ignore individual checks
D. Return Health.up() if both checks pass; else Health.down() with details for each failure

Solution

  1. Step 1: Understand combined health logic

    The health status should be UP only if both database and cache are reachable; otherwise DOWN.
  2. Step 2: Implement conditional return with details

    Return Health.up() if both pass; else return Health.down() and include details explaining which failed.
  3. Final Answer:

    Return Health.up() if both checks pass; else Health.down() with details for each failure -> Option D
  4. Quick Check:

    Combined checks control status UP or DOWN with details [OK]
Hint: Return UP only if all checks pass; else DOWN with failure details [OK]
Common Mistakes:
  • Returning UP regardless of failures
  • Ignoring combined status logic
  • Splitting checks without combining results
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