Fork me on GitHub

Spring Web MVC Procedure Tutorial

This tutorial demonstrates configuring a Spring Web MVC Controller as a procedure.

Adding a Spring Web MVC Controller as a procedure, allows re-use of existing code. Ideally, over time, the Spring Web MVC Controllers are simplified to methods taking advantage of OfficeFloor's IoCC. However, Spring Web MVC Controllers are supported as procedures to avoid significant rewrites of application code. This enables taking advantage of OfficeFloor's features with existing Spring code.

Tutorial Source

Configuring Spring Web MVC Controller

Please see the Spring Web MVC Controller Tutorial regarding configuring Spring Web MVC Controllers into WoOF. The tutorial needs to be followed to also enable Spring Web MVC Controllers to be configured as procedures.

Configuring as a Procedure

Select the Spring Web MVC Controller as a class when adding a procedure.

Note: the Controller must be on the application's Spring scan path.

The tutorial configuration is as follows:

SpringWebMvcHttpServer configuration.

Note that the WoOF configured paths can be different to the Spring Web MVC Controller request mappings. The only constraint on this is that the path parameters must match.

Testing

The following tests demonstrates the procedures.

	@RegisterExtension
	public static final MockWoofServerExtension server = new MockWoofServerExtension();

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

	@Test
	public void pathParam() {
		MockWoofResponse response = server.send(MockWoofServer.mockRequest("/officefloor/changed/parameter"));
		response.assertJson(200, new ResponseModel("parameter"));
	}

	@Test
	public void put() {
		MockWoofResponse response = server
				.send(MockWoofServer.mockJsonRequest(HttpMethod.PUT, "/officefloor/update", new RequestModel("INPUT")));
		response.assertJson(200, new ResponseModel("INPUT"));
	}

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

Next

The next tutorial covers migrating Spring Web MVC Controllers for simpler code and avoid the dependency on Spring.