Difficulty: Beginner
Estimated Time: 15 minutes

Do you want to create a reactive Spring controller? Then, you're at the right place!

In this scenario, we'll learn how to:

  • Create a Spring project with Spring Initializr
  • Create the Owner entity from the Spring Pet Clinic example
  • Create an API endpoint
  • Create a reactive service
  • Use Swagger UI to access the API

This scenario is a subset of the full Reactive Spring Pet Clinic project that focuses on the controller for a single entity. Note that Reactive programming is a bit more advanced, so it may be helpful to review the basic Spring Pet Clinic example in preparation for this scenario. Here's an architectural diagram of what we will build.

Architectural Diagram

ver 0.001

This scenario we created a Reactive Spring REST API controller for a single entity.

In this scenario, we learned how to:

  • Create a Spring project with Spring Initializr
  • Create the Owner entity from the Spring Pet Clinic example
  • Create an API endpoint
  • Create a reactive service
  • Use Swagger UI to access the API

This scenario focused on the controller for a single entity of the Reactive Spring Pet Clinic example to isolate and identify the necessary components. Check out the other scenarios in the Reactive Spring Pet Clinic course for further Reactive Spring ideas.

Build a Reactive Spring REST Service Controller

Step 1 of 8

Run Spring Initiailizr

We'll start our project by using Spring Initializr to configure the project.


NOTE: To simplify our lives with Katacoda, we have already run Spring Initializr and downloaded its resulting zip file to the Katacoda VM. But, we'll walk you through the Spring Initializr process anyway so you understand what we did.


You can find Spring Initializr here.

Fill out the project metadata as shown including adding the Spring Boot DevTools and Spring Reactive Web dependencies.


NOTE: Spring Initializr may have software versions that are more recent than those shown in the image. If the version numbers differ from those in the image, just use the default version numbers.


Spring initializr

Normally, you would click the Generate button to create the zip file, but we have done that for you.

Let's unzip the Spring Initializr project.

unzip spring-petclinic-reactive.zip

The project actually runs at this point, although it doesn't do anything. Let's run it anyway just to see everything compile and run.

export JAVA_HOME="/usr/lib/jvm/default-java"
cd /root/spring-petclinic-reactive
mvn spring-boot:run

The purpose of running the project at this point is to make sure everything compiles and to show that Spring Initializr created a runnable project. You can access the running server by clicking on the link below, but you will see an error like the following.

WhiteLabelError

This error is OK. It merely means that we haven't yet configured the API to respond. We'll address this in the next step.

Great! We have a basic server running.