0
0
Spring Bootframework~20 mins

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

Choose your learning style9 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.