Let's start by creating a new project using SPRING INITIALIZR (http://start.spring.io/). The following screenshot shows the details:
A few things to note are as follows:
- Group: com.mastering.spring.reactive
- Artifact: spring-reactive-example
- Dependencies: ReactiveWeb (to build a reactive web application) and DevTools (for auto-reload when the application code is changed)
Click Generate, and import the project into your IDE as a Maven project.
Important dependencies in the pom.xml file are as follows:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
The spring-boot-starter-webflux dependency is the most important dependency for Spring Web Reactive. The following snippet shows the dependencies defined in spring-boot-starter-webflux:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-reactor-netty</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>
The preceding snippet shows the important building blocks of Spring Reactive—spring-webflux, spring-web, and spring-boot-starter-reactor-netty. Netty is the default embedded Reactive server.