Reputation: 13323
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?
Upvotes: 10
Views: 14138
Reputation: 2594
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();
Upvotes: 12
Reputation: 59211
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.
Note that there's an existing issue about supporting Jetty Client as an alternative, see SPR-15092.
Upvotes: 3