According to the documentation it is possible to use the Spring Reactive WebClient with a different server as Netty:
WebClient provides a higher level API over HTTP client libraries. By default it uses Reactor Netty but that is pluggable with a different ClientHttpConnector.
However, I was not able to find a way how to do this. If I simply change the dependency from Netty to Jetty like this:
compile('org.springframework.boot:spring-boot-starter-webflux') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-reactor-netty'
}
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty', version: '2.0.0.M5'
my application will fail to start:
2017-10-30 15:40:43.328 ERROR 20298 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
java.lang.NoClassDefFoundError: reactor/ipc/netty/http/client/HttpClient
Obviously I need to do something more. But this github issue gives me the impression that WebClient cannot be used without Netty.
Is it possible to replace the Netty implementation of WebClient?
Generally you need to exclude the default embedded Tomcat server that comes with Spring Boot framework and use the Jetty starter in the dependency either in maven’s pom.xml file or gradle’s build.gradle file. So you have seen how to use Jetty instead of Tomcat in Spring Boot application. Now you can build and run your application on Jetty server.
The Spring WebClient API must be used on top of an existing asynchronous HTTP client library. In most cases that will be Reactor Netty, but you can also use Jetty Reactive HttpClient or Apache HttpComponents, or integrate others by building a custom connector. Once these are installed, you can send your first GET request in WebClient:
last modified July 9, 2020 Spring Jetty tutorial shows how to run Spring web application on Jetty web server. Springis a popular Java application framework for creating enterprise applications. Jetty
Right now, in Spring Framework, WebClient has only one available ClientHttpConnector implementation, which is powered by Reactor Netty. This explains the current situation - using WebClient means you need Reactor Netty as a dependency.
Add dependency:
org.eclipse.jetty:jetty-reactive-httpclient:1.0.3
And then:
HttpClient httpClient = new HttpClient();
ClientHttpConnector connector = new JettyClientHttpConnector(httpClient);
WebClient webClient = WebClient.builder().clientConnector(connector).build();
Source: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-client-builder-jetty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With