如何从APACHE Http客户端创建Spring WebClient [英] How to create Spring WebClient from Apache Http Client
本文介绍了如何从APACHE Http客户端创建Spring WebClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从HttpComponent的org.apache.http.client.HttpClient创建WebClient,以便在异步操作中使用它。有关如何操作的任何想法
推荐答案
随着Spring Framework5.3和Spring Boot2.4的发布,现在在ApacheHttpClient5.0和Spring WebClient之间有内置集成。
HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
clientBuilder.setDefaultRequestConfig(...);
CloseableHttpAsyncClient client = clientBuilder.build();
ClientHttpConnector connector = new HttpComponentsClientHttpConnector(client);
WebClient webClient = WebClient.builder().clientConnector(connector).build();
更新(基于@kolyaiks的评论)
必需的依赖项:
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-reactive</artifactId>
<version>5.1</version>
</dependency>
这篇关于如何从APACHE Http客户端创建Spring WebClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文