根据文档可以将 Spring Reactive WebClient 与 Netty 等不同的服务器一起使用:
WebClient 通过 HTTP 客户端库提供更高级别的 API。经过
默认它使用 Reactor Netty,但可以使用不同的插件进行插入
客户端Http连接器。
但是,我无法找到如何做到这一点的方法。如果我简单地将依赖关系从 Netty 更改为 Jetty,如下所示:
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'
我的应用程序将无法启动:
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问题给我的印象是没有Netty就无法使用WebClient。
是否可以替换WebClient的Netty实现?
添加依赖:
org.eclipse.jetty:jetty-reactive-httpclient:1.0.3
进而:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)