Tested converting an existing integration test that was using TestRestTemplate into integration test using WebTestClient
package no.mycompany.myapp.user;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;
@AutoConfigureWebTestClient
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class LoginControllerTest {
@Autowired
WebTestClient webTestClient;
@Test
public void postLogin_withoutUserCredentials_receiveUnauthorized() {
webTestClient.post()
.uri("/login")
.exchange()
.expectStatus().isUnauthorized();
}
}
Added this to POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
The following was already in POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Answer from Roar S. on Stack OverflowBaeldung
baeldung.com › home › spring › spring web › spring webclient
Spring WebClient | Baeldung
November 25, 2025 - Since we are using a Spring Boot application, all we need is the spring-boot-starter-webflux dependency to obtain Spring Framework’s Reactive Web support.
Getting Started with the Web Client in Spring Boot & Writing Tests
08:03
How to Call a REST API using WebClient in Spring Boot - YouTube
27:35
Tutorial #18 | Spring Boot WebClient | Hands on | Spring Webflux ...
25:28
Calling REST Services with WebClient Spring Boot | Microservices ...
23:33
Spring WebClient Tutorial #springboot #java #100dayschallenge - ...
josdem
josdem.io › home › spring boot web client
Spring Boot WebClient -
July 25, 2024 - buildscript { ext { springBootVersion = '2.1.0.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.jos.dem.springboot.webclient' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { implementation('org.springframework.boot:spring-boot-starter-webflux') compileOnly('org.projectlombok:lombok') testImplementation('org.springframework.boot:spring-boot-starter-test') testImplementation('io.projectreactor:reactor-test') }
Spring
docs.spring.io › spring-framework › reference › web › webflux-webclient.html
WebClient :: Spring Framework
WebClient needs an HTTP client library to perform requests.
Top answer 1 of 2
6
You need to include reactor-netty on the classpath. As by default that is the HTTP client used by WebClient.
pom.xml:
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>
More info: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-client
2 of 2
0
No worry option would be adding
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
Spring
docs.spring.io › spring-boot › docs › 2.1.x › reference › html › boot-features-webclient.html
37. Calling REST Services with WebClient
The spring-boot-starter-webflux starter depends on io.projectreactor.netty:reactor-netty by default, which brings both server and client implementations. If you choose to use Jetty as a reactive server instead, you should add a dependency on the Jetty Reactive HTTP client library, org.eclipse.jetty:jetty-reactive-httpclient.
Maven Central
central.sonatype.com › artifact › org.springframework.boot › spring-boot-starter-webclient
Maven Central: org.springframework.boot:spring-boot-starter-webclient
Dependencies · Starter using Spring's reactive HTTP clients (WebClient and HTTP Service Clients) Copy to clipboard · <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webclient</artifactId> <version>4.2.0-M1</version> </dependency> Copy to clipboard ·
Medium
selvaseamers.medium.com › a-comprehensive-guide-to-using-webclient-in-java-spring-configuring-client-oauth2-custom-5beb686ab7d1
A Comprehensive Guide to Using WebClient in Java Spring: Configuring Client OAuth2, Custom…
April 3, 2023 - <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-client</artifactId> </dependency> With these dependencies added, we can now define our WebClient bean with the required configurations:
Spring
docs.spring.io › spring-boot › docs › 2.1.8.RELEASE › reference › html › boot-features-webclient.html
36. Calling REST Services with WebClient
The spring-boot-starter-webflux starter depends on io.projectreactor.netty:reactor-netty by default, which brings both server and client implementations. If you choose to use Jetty as a reactive server instead, you should add a dependency on the Jetty Reactive HTTP client library, org.eclipse.jetty:jetty-reactive-httpclient.
GitHub
github.com › spring-projects › spring-boot › issues › 34198
How can I get a WebClient without a required dependency to any web server? · Issue #34198 · spring-projects/spring-boot
February 15, 2023 - I want to use a Flux WebClient in a reuse-library. This library is a web-client only and should not include any http-server component. My library is to be used in console / shell applications, which also have no use for any http-server component. I know that It is possible to configure the http-client. But it seems, you can not have the http-client without the server. If I take out the dependency to the webflux-starter, and work with the spring-webflux dependency only, I get the error message:
Author: spring-projects