Spring Boot 4 cheatsheet

Spring Boot 4: Actuator and testing

5 common Spring Boot 4 tasks.

Expose Actuator endpoints

Choose which Actuator endpoints are available over HTTP.

management.endpoints.web.exposure.include=health,info,metrics

Check application health

Call the health endpoint, for example from a load balancer or Kubernetes probe.

curl http://localhost:8080/actuator/health

Run the tests

Run the unit and integration tests.

./mvnw test

Write an integration test

Start the full application context for a test.

@SpringBootTest
class DemoApplicationTests {

    @Test
    void contextLoads() {
    }
}

Test a controller

Load only the web layer and call it with MockMvc.

@WebMvcTest(UserController.class)
class UserControllerTest {

    @Autowired MockMvc mvc;

    @Test
    void returnsUser() throws Exception {
        mvc.perform(get("/api/users/1")).andExpect(status().isOk());
    }
}

Was this page helpful?