I have a very limited need to be able to make HTTP request. I see WebClient is the new replacement for RestTemplate. But it seems it is impossible to use WebClient, without dragging in the whole of spring boot; which is not what I want to do. Any way to use WebClient without Spring boot?
Asked
Active
Viewed 5,555 times
11
-
Maybe it's not possible to do or to use the spring WebClient module without the spring module project, because it provides for you the configuration ! – Rebai Ahmed Sep 04 '20 at 13:07
2 Answers
16
You can make asynchronous HTTP request using Reactor Netty HttpClient (docs). Spring WebClient uses it under the hood. Just add dependency
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.9.11.RELEASE</version>
</dependency>
and make request
HttpClient.create()
.request(HttpMethod.GET)
.uri("http://example.com/")
.responseContent()
.asString()
.subscribe(System.out::println);

mikhail.sharashin
- 349
- 3
- 10
-
Thanks for this answer. I will test it out in a bit. I just have a clarifying question...How is using this different from using the new Httpclient in Java 11? (I am stuck on Java 8, that is why I cannot even use that). From where I stand, it seems the http client from project reactor and Java 11 all implement the same reactive streams. So one from project reactor is the spring implementation, while the one from Java 11 is the JDK implementation. Will this be correct? – Finlay Weber Sep 05 '20 at 13:16
-
1I replaced my usage of WebClient with the suggested HttpClient and all works fine. I am accepting this answer, although technically it is not an answer to how to use Spring WebClient without Spring Boot - which I think it is impossible. – Finlay Weber Sep 05 '20 at 18:03
-
-5
I had the same problem and I solved it doing this.
You need to create a logback.xml file in the src / main / resources folder and copy this
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
</configuration>
If you already have this file just add this statusLIstener inside your configuration.

Gerard Puig
- 11
- 3