0
0
Spring Bootframework~10 mins

Health checks in Docker in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a simple health check endpoint in Spring Boot.

Spring Boot
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HealthController {
    @GetMapping("/health")
    public String [1]() {
        return "OK";
    }
}
Drag options to blanks, or click blank then click option'
Ahealth
BcheckHealth
ChealthCheck
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated method names that confuse the purpose.
2fill in blank
medium

Complete the Dockerfile line to add a health check that calls the Spring Boot health endpoint.

Spring Boot
HEALTHCHECK --interval=30s --timeout=5s CMD curl -f http://localhost:8080/[1] || exit 1
Drag options to blanks, or click blank then click option'
Astatus
Bhealth
Cping
Dcheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect endpoint paths that cause health check failures.
3fill in blank
hard

Fix the error in the Dockerfile health check command to correctly check the Spring Boot app health.

Spring Boot
HEALTHCHECK --interval=30s --timeout=5s CMD curl -f http://localhost:8080/[1] || exit 1
Drag options to blanks, or click blank then click option'
Alive
Bhealthz
Cstatus
Dhealth
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent endpoints causing health check failures.
4fill in blank
hard

Fill both blanks to create a Spring Boot actuator health check configuration and Dockerfile health check command.

Spring Boot
management.endpoint.health.[1]=true
HEALTHCHECK --interval=30s CMD curl -f http://localhost:8080/actuator/[2] || exit 1
Drag options to blanks, or click blank then click option'
Aenabled
Bdisabled
Chealth
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Disabling the endpoint or using wrong endpoint paths.
5fill in blank
hard

Fill all three blanks to define a custom health indicator bean and use it in the health endpoint.

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 [1]() {
        boolean serverUp = checkServer();
        if (serverUp) {
            return Health.[2]().withDetail("server", "Up").build();
        } else {
            return Health.[3]().withDetail("server", "Down").build();
        }
    }

    private boolean checkServer() {
        // Custom logic here
        return true;
    }
}
Drag options to blanks, or click blank then click option'
Ahealth
Bup
Cdown
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Wrong method names or using incorrect Health status methods.