Spring Boot 3 REST HTTP Server Tutorial

OfficeFloor provides version-specific REST starters so that each Spring Boot generation receives a JAR compiled and validated against that exact runtime. This tutorial demonstrates how to add OfficeFloor REST to an existing Spring Boot 3 application by declaring the correct starter.

Tutorial Source

Choosing the right starter

Two artifacts are published — one per supported Spring Boot generation:

Spring Boot version Starter artifact
Spring Boot 3.x officefloor-rest-spring-boot-3-starter
Spring Boot 4.x officefloor-rest-spring-boot-4-starter

Each starter is compiled against its target Spring Boot version, so its classes are binary compatible with the runtime you already have. Mixing versions — e.g., pulling the 4-starter into a Spring Boot 3 project — can cause NoSuchMethodError or other binary incompatibilities at runtime.

To check which Spring Boot version your project uses, look at the parent block or the spring-boot-dependencies import in your pom.xml.

Maven dependency for Spring Boot 3

Add only the one starter that matches your Spring Boot generation. Everything else — spring-boot-starter-web and the rest of your existing dependencies — is unchanged:

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

The officefloor-rest-spring-boot-3-starter auto-configures OfficeFloor into the Spring MVC pipeline exactly as the Spring Boot 4 starter does. On start-up it scans the classpath for YAML files under officefloor/rest/ and registers each as a handler for the corresponding HTTP method and URL path. No additional Java or XML configuration is needed.

Application class

The application entry point is an ordinary @SpringBootApplication class — no OfficeFloor annotation is required:

@SpringBootApplication
public class Application {

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

YAML endpoint file

Endpoints are declared as YAML files under src/main/resources/officefloor/rest/. The file path mirrors the URL and the file name suffix is the HTTP method:

officefloor/rest/
└── greeting.GET.yml     →  GET  /greeting
service:
  class: net.officefloor.tutorial.springrestspringboot3server.GreetingLogic

The service label is the developer-chosen step name. The class value names the Java class that handles the request. OfficeFloor calls the single public method on that class.

Service logic with Spring injection

The handler receives Spring beans as plain method parameters — no @Autowired annotation is needed. ObjectResponse<T> serialises the return value as JSON:

public class GreetingLogic {

	public void service(GreetingService greetingService, ObjectResponse<GreetingResponse> response) {
		response.send(new GreetingResponse(greetingService.greet("World")));
	}
}

The injected GreetingService is a standard Spring @Service:

@Service
public class GreetingService {

	public String greet(String name) {
		return "Hello from Spring Boot 3, " + name + "!";
	}
}

The response DTO is a plain Java class:

@Data
@NoArgsConstructor
@AllArgsConstructor
public class GreetingResponse {

	private String message;
}

Testing

Tests use the standard Spring Boot 3 test stack. @AutoConfigureMockMvc is at its Spring Boot 3 package (org.springframework.boot.test.autoconfigure.web.servlet):

@SpringBootTest
@AutoConfigureMockMvc
public class SpringBoot3HttpServerTest {

	@Autowired
	private MockMvc mvc;

	@Autowired
	private ObjectMapper mapper;

	@Test
	public void getGreeting() throws Exception {
		mvc.perform(MockMvcRequestBuilders.get("/greeting")
				.accept(MediaType.APPLICATION_JSON))
				.andExpect(status().isOk())
				.andExpect(content().json(mapper.writeValueAsString(new GreetingResponse("Hello from Spring Boot 3, World!"))));
	}
}

Migrating from Spring Boot 3 to Spring Boot 4

When you are ready to upgrade your application to Spring Boot 4, the only OfficeFloor change is swapping the starter artifact ID:

<!-- Before (Spring Boot 3) -->
<artifactId>officefloor-rest-spring-boot-3-starter</artifactId>

<!-- After (Spring Boot 4) -->
<artifactId>officefloor-rest-spring-boot-4-starter</artifactId>

All YAML endpoint files, service logic classes, and test code remain identical. The two starters expose the same auto-configuration API so the rest of your codebase does not need to change.

The Spring REST HTTP Server tutorial shows the full feature set (path variables, composed steps, conditional routing) using the Spring Boot 4 starter. Everything demonstrated there applies equally to the Spring Boot 3 starter.

Next

The Function Injection tutorial explores function injection more deeply: a three-step pipeline with conditional branching, typed data passing between steps, and independent Spring service injection at each step.