Spring Boot Reactive Tutorial

1. Overview

Spring 5, which will release later this year, will support building asynchronous and Reactive applications.

This is a simple tutorial showing the new features in Spring and how to create a web application. The application will connect to a database, have basic authentication, and be Reactive.

2. Reactive Programming

Reactive programming is about building asynchronous, non-blocking, and event-driven applications that can easily scale.

Each event is published to subscribers while ensuring that the subscribers are never overwhelmed.

Mono and Flux are implementations of the Publisher interface.
A Flux will observe 0 to N items and eventually terminate successfully or not.
A Mono will observe 0 or 1 item, with Mono<Void> hinting at most 0 items.

To learn more about Reactive Programming, you can refer to this article.

3. Dependencies

We’ll use Gradle to build our project. I recommend using Spring Initializr for bootstrapping your project.

We’ll use:

Spring Boot 2

Spring Webflux

Spring Reactive Data MongoDB

Spring Security Reactive Webflux

Lombok

Not all the Spring libraries have a stable release yet.

Lombok is used to reduce boilerplate code for models and POJOs. It can generate setters/getters, default constructors, toString, etc. methods automatically.