Fork me on GitHub

Spring Web MVC Tutorial

This tutorial demonstrates configuring Spring Web MVC Controllers within WoOF. This enables using an existing Spring Application out of the box within WoOF.

Tutorial Source

Spring Web MVC Controller

The Spring Web MVC Controller to be integrated is as follows:

public class SpringRestController {

	private SpringDependency dependency;

	public ResponseModel get() {
		return new ResponseModel("GET " + this.dependency.getMessage());

	public ResponseModel path(@PathVariable String param) {
		return new ResponseModel(param);

	public ResponseModel post(@RequestBody RequestModel request) {
		return new ResponseModel(request.getInput());


With the request and response models:

public class RequestModel {

	private String input;
public class ResponseModel {

	private String message;

Configuring Spring Web MVC Controller

To configure using Spring Web MVC Controller instances within WoOF, add the following dependency:


Spring will also need to be configured in application.objects:

	<supplier source="SPRING">
		<property name="configuration.class" value="net.officefloor.tutorial.springwebmvchttpserver.Application" />


This will have all the Spring Web MVC Controllers available at their request mapped paths.

Spring web pages

Integration of Spring Web MVC Controllers is not limited to only REST. The following Spring Web MVC Controller:

public class SpringController {

	public String html(@RequestParam String name, Model model) {
		model.addAttribute("name", name);
		return "simple";

Provides the following web page:

<html><body><p th:text="'Hello ' + ${name}" /></body></html>


The following tests demonstrate the Spring Web MVC Controllers servicing requests.

	public static final MockWoofServerExtension server = new MockWoofServerExtension();

	public void get() {
		MockWoofResponse response = server.send(MockWoofServer.mockRequest("/rest"));
		response.assertJson(200, new ResponseModel("GET Spring Dependency"));

	public void pathParam() {
		MockWoofResponse response = server.send(MockWoofServer.mockRequest("/rest/path/parameter"));
		response.assertJson(200, new ResponseModel("parameter"));

	public void post() {
		MockWoofResponse response = server
				.send(MockWoofServer.mockJsonRequest(HttpMethod.POST, "/rest/update", new RequestModel("INPUT")));
		response.assertJson(200, new ResponseModel("INPUT"));

	public void html() {
		MockWoofResponse response = server.send(MockWoofServer.mockRequest("/html?name=Daniel"));
		response.assertResponse(200, "<html><body><p >Hello Daniel</p></body></html>");


The next tutorial covers configuring a Spring Web MVC Controller as a procedure.