0
0
Spring Bootframework~10 mins

Custom actuator endpoints 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 custom actuator endpoint class.

Spring Boot
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;

@[1](id = "custom")
public class CustomEndpoint {

    @ReadOperation
    public String custom() {
        return "Hello from custom endpoint!";
    }
}
Drag options to blanks, or click blank then click option'
AService
BComponent
CEndpoint
DController
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @Endpoint
Forgetting to specify the id in the annotation
2fill in blank
medium

Complete the code to register the custom endpoint as a Spring bean.

Spring Boot
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EndpointConfig {

    @Bean
    public CustomEndpoint [1]() {
        return new CustomEndpoint();
    }
}
Drag options to blanks, or click blank then click option'
AcustomEndpoint
Bendpoint
Ccustom
DcustomActuator
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name as the endpoint id
Using uppercase letters at the start
3fill in blank
hard

Fix the error in the method that exposes the endpoint data.

Spring Boot
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;

public class CustomEndpoint {

    @ReadOperation
    public String [1]() {
        return "Custom data";
    }
}
Drag options to blanks, or click blank then click option'
Afetch
Bcustom
Cread
DgetData
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that conflict with Spring reserved names
Using verbs that are not descriptive
4fill in blank
hard

Fill both blanks to create a custom actuator endpoint that returns a map with status and message.

Spring Boot
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import java.util.Map;

@[1](id = "status")
public class StatusEndpoint {

    @[2]
    public Map<String, String> status() {
        return Map.of("status", "UP", "message", "All systems go");
    }
}
Drag options to blanks, or click blank then click option'
AEndpoint
BReadOperation
CComponent
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up @Component with @Endpoint
Forgetting to annotate the method
5fill in blank
hard

Fill all three blanks to create a custom actuator endpoint that accepts a path variable and returns a greeting message.

Spring Boot
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;

@[1](id = "greet")
public class GreetEndpoint {

    @[2]
    public String greet(@[3] String name) {
        return "Hello, " + name + "!";
    }
}
Drag options to blanks, or click blank then click option'
AEndpoint
BReadOperation
CSelector
DComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use @Selector for the method parameter
Using @Component instead of @Endpoint