Closed pkubowicz closed 3 years ago
WebTestClient
is a test wrapper around WebClient
. The very first link of the section you've referenced points to the WebClient
section that's part of Spring Webflux. I've transferred your issue to Spring Framework to determine if the doc could be more explicit about this.
Rather than only improving documentation, it would be much better if Spring could show a better message to the user.
Something in the lines of
Injection ... failed; you probably wanted to declare webflux dependencies in your pom.xml or build.gradle
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/reactive/function/client/ExchangeFunction
at ...
After reading release notes for Spring Framework 5.3 and the Reference Documentation I wanted to use WebTestClient in a Spring MVC application, but it fails with:
Reproducing
build.gradle
GreetingController.java
GreetingControllerTest.java
Workaround
Add webflux dependency:
I think it's a bug in code or at least a bug in documentation. The documentation does not mention in any place that you need WebFlux to test your MVC applications. This is an idea that looks absurd at first sight, so if it is really the case, it should be explicitly explained that you really need to do it.