Fork me on GitHub

Migrate Spring Web Flux Tutorial

This tutorial provides the typical steps in migrating a Spring Web Flux Controller to avoid dependency on Spring. It also enables simpler code that can take advantage of all the OfficeFloor features.

Tutorial Source

Steps to migrate a Spring Web Flux Controller

The Spring Web Flux Controller to be migrated is taken from the previous tutorial:

@RestController
@RequestMapping("/rest")
public class SpringRestController {

	@Autowired
	private SpringDependency dependency;

	@GetMapping
	public Mono<ResponseModel> get() {
		return Mono.just(new ResponseModel("GET " + this.dependency.getMessage()));
	}

	@GetMapping("/path/{param}")
	public Mono<ResponseModel> path(@PathVariable String param) {
		return Mono.just(new ResponseModel(param));
	}

	@PostMapping("/update")
	public Flux<ResponseModel> post(@RequestBody RequestModel request) {
		return Flux.just(new ResponseModel(request.getInput()), new ResponseModel("ANOTHER"));
	}

}

To migrate a Spring Web Flux Controller:

1. Replace the Spring parameter annotations with WoOF annotations.

2. Provide Reactor OfficeFloor integration by adding following dependency (see Reactor tutorial for further details):

		<dependency>
			<groupId>net.officefloor.reactor</groupId>
			<artifactId>officereactor</artifactId>
		</dependency>

3. Remove @ResponseBody and configure next procedure to send result as parameter via ObjectResponse:

public class SendResponse {

	public void send(@Parameter ResponseModel payload, ObjectResponse<ResponseModel> response) {
		response.send(payload);
	}
}

4. Any @PostContruct / @PreDestroy moved to ManagedObjectSource as injected object.

5. See Transaction Tutorial for graphically configuring transactions (removing need for Spring's @Transactional).

6. Remove the remaining Spring annotations.

7. Move dependencies to parameters of the method.

The resulting migrated code is as follows:

public class MigratedRestController {

	public Mono<ResponseModel> get(SpringDependency dependency) {
		return Mono.just(new ResponseModel("GET " + dependency.getMessage()));
	}

	public Mono<ResponseModel> path(@HttpPathParameter("param") String param) {
		return Mono.just(new ResponseModel(param));
	}

	public Mono<ResponseModel> post(RequestModel request) {
		return Mono.just(new ResponseModel(request.getInput()));
	}

}

Next

The next tutorial covers migrating WAR application.