Spring 5.0 Projects
上QQ阅读APP看书,第一时间看更新

Spring WebFlux application

We will create a sample web application with the WebFlux framework. The application will simply access existing student information from a data store. Instead of making a fully fledged application, we will focus more on how to access data in a reactive manner with the WebFlux framework.

We will use Spring Boot to kickstart the development. For those who are new to Spring Boot, it is a tool and part of Spring Horizon, which is designed to speed up and simplify the bootstrapping and development of new Spring-based applications.

You might have come across bulky XML and other configurations repeatedly in Spring projects. The Spring team was well aware of this and has finally developed a tool called Spring Boot, aimed at freeing the developer from providing a boilerplate configuration, which is not only tedious but time consuming.

We will create a sample web application using MongoDB as a data store. While working with Reactive Programming, it is recommended to use non-blocking and reactive capable datastores, like MongoDB, Couchbase, Cassandra, and so on. We will use a tool called Spring Tool Suite (STS), which is an Eclipse-based IDE. It provides support for creating Spring Boot-based applications. Download it from: https://spring.io/tools3/sts/all and install it in your local machine. 

The STS link given here is version 3.x. At the time of writing, the current version of STS is 4.x. All the codes created in this book are with STS 3.x so the link given is version 3.x. However, you can download the latest version of STS and play with the code without any problems. 

Once downloaded, open it, select the File | New | Spring Starter Project menu and fill the form as follows:

Click on the Next button, and you will be asked to define the dependencies. Choose the following dependencies. You can use the textbox, Available to search for a particular dependency:

  • Web: Used to add Spring MVC specific dependencies.
  • Reactive Web: To add WebFlux specific dependencies.
  • DevTools: Helpful for development as it will auto-refresh the changes in the embedded container to see the changes quickly. 
  • Reactive MongoDB: Spring Data dependency for MongoDB that works in a reactive paradigm. Make sure you don't select MongoDB, which is a dependency to work with MongoDB in the non-reactive model.

Click on Finish, and you will see a project is created in the Package Explorer (or Project Explorer) section of STS. Once the project is created, we will perform the following steps.