Spring Webflux Client

In previous Spring Boot Server we covered web reactive server, this time we will see the client side. Let’s start creating a new project with Webflux, Mongo Reactive and Lombok as dependencies:

spring init --dependencies=webflux,data-mongodb-reactive,lombok --build=gradle --language=java client

Here is the complete build.gradle file generated:

buildscript {
  ext {
    springBootVersion = '2.1.0.RELEASE'
  repositories {
  dependencies {

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.jos.dem.webflux'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {

dependencies {

Now let’s create a simple POJO to retrieve information from our reactive server.

package com.jos.dem.webflux.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

public class Person {

  private String uuid;
  private String nickname;
  private String email;


Lombok is a great tool to avoid boilerplate code, for knowing more please go here. Next, we are going to use CommandLineRunner to start our workflow. The CommandLineRunner is a call back interface in Spring Boot, when Spring Boot starts will call it and pass in args through a run() internal method.

package com.jos.dem.webflux;

import org.springframework.context.annotation.Bean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.function.client.WebClient;

import com.jos.dem.webflux.model.Person;

public class PersonApplication {

  public static void main(String[] args) {
    SpringApplication.run(PersonApplication.class, args);

  WebClient webClient() {
    return WebClient.create("http://localhost:8080/persons");

  CommandLineRunner run(WebClient client){
    return args -> {


WebClient defined as @Bean is a non-blocking, reactive client for performing HTTP requests with our reactive web server, and again Netty is used by default. Do not forget to run this client in different port using the following specification in our application.properties file


To run the project:

gradle bootRun

To run the project with Maven:

mvn spring-boot:run

To browse the project go here, to download the project:

git clone https://github.com/josdem/reactive-webflux-workshop.git
git fetch
git checkout feature/client

Return to the main article

comments powered by Disqus