如何通过Jetty而不是Netty使用Spring WebClient? [英] How to use the Spring WebClient with Jetty, instead of Netty?

查看:288
本文介绍了如何通过Jetty而不是Netty使用Spring WebClient?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,可以将Spring Reactive WebClient与其他服务器(如Netty)一起使用:

According to the documentation it is possible to use the Spring Reactive WebClient with a different server as Netty:

WebClient通过HTTP客户端库提供了更高级别的API.经过 默认情况下,它使用Reactor Netty,但是可以用其他插件插入 ClientHttpConnector.

WebClient provides a higher level API over HTTP client libraries. By default it uses Reactor Netty but that is pluggable with a different ClientHttpConnector.

但是,我无法找到一种方法来做到这一点.如果我像这样简单地将依赖从Netty更改为Jetty:

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

显然,我需要做更多的事情.但这 github问题给我的印象是WebClient不能不使用净额.

Obviously I need to do something more. But this github issue gives me the impression that WebClient cannot be used without Netty.

是否可以替换WebClient的Netty实现?

Is it possible to replace the Netty implementation of WebClient?

推荐答案

目前,在Spring Framework中,WebClient只有一个可用的ClientHttpConnector实现,该实现由Reactor Netty提供支持.这解释了当前的情况-使用WebClient意味着您需要Reactor Netty作为依赖项.

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.

请注意,存在关于支持Jetty Client的替代问题,请参见 SPR-15092 .

Note that there's an existing issue about supporting Jetty Client as an alternative, see SPR-15092.

这篇关于如何通过Jetty而不是Netty使用Spring WebClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆