Fork me on GitHub

Spring Actuator with OfficeFloor REST

Spring Boot Actuator provides production-ready endpoints — health, info, metrics and more — that operations teams depend on for monitoring and readiness checks.

Adding OfficeFloor REST YAML endpoints alongside Actuator requires no extra configuration. OfficeFloor registers its endpoints via Spring MVC's HandlerInterceptor mechanism, which sits completely outside Actuator's endpoint management. Both route through the same servlet without interfering with each other.

This tutorial demonstrates a Spring Boot application that exposes a custom OfficeFloor REST endpoint at GET /status while Actuator's GET /actuator/health continues to work unchanged.

Tutorial Source

Maven dependency

Add spring-boot-starter-actuator alongside the OfficeFloor starter:

		<dependency>
			<groupId>net.officefloor.springboot</groupId>
			<artifactId>officefloor-rest-spring-boot-starter</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

Exposing Actuator endpoints

By default Spring Boot only exposes the health and info endpoints over HTTP. Expand the set in application.properties as needed:

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

Application class

@SpringBootApplication
public class SpringRestActuatorApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringRestActuatorApplication.class, args);
	}
}

OfficeFloor REST endpoint

The YAML file declares the GET /status endpoint in the usual way:

service:
  class: net.officefloor.tutorial.springrestactuator.StatusLogic

The logic class is a plain Java method:

public class StatusLogic {

	public void service(ObjectResponse<StatusResponse> response) {
		response.send(new StatusResponse("running"));
	}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class StatusResponse {

	private String status;
}

Testing

Both the OfficeFloor REST endpoint and the Actuator health endpoint are verified in the same test:

@SpringBootTest
@AutoConfigureMockMvc
public class SpringRestActuatorHttpServerTest {

	@Autowired
	private MockMvc mvc;

	@Autowired
	private ObjectMapper mapper;

	@Test
	public void officefloorEndpointWorks() throws Exception {
		mvc.perform(get("/status").accept(MediaType.APPLICATION_JSON))
				.andExpect(status().isOk())
				.andExpect(content().json(mapper.writeValueAsString(new StatusResponse("running"))));
	}

	@Test
	public void actuatorHealthEndpointWorks() throws Exception {
		mvc.perform(get("/actuator/health").accept(MediaType.APPLICATION_JSON))
				.andExpect(status().isOk())
				.andExpect(jsonPath("$.status").value("UP"));
	}
}

officefloorEndpointWorks confirms the YAML-declared endpoint is reachable. actuatorHealthEndpointWorks confirms Actuator remains fully operational alongside it.

What you have now

After completing this tutorial you can:

  • Add spring-boot-starter-actuator to an application that already uses the OfficeFloor REST starter without any additional configuration
  • Rely on health, info, and other Actuator endpoints working unchanged
  • Expose Actuator endpoints selectively via management.endpoints.web.exposure.include

Next

The Spring HTTP Server tutorial shows how to host your Spring beans inside the OfficeFloor runtime, unlocking further OfficeFloor capabilities while keeping all existing Spring configuration.