本文介紹了如何從APACHE Http客戶端創(chuàng)建Spring WebClient的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我想從HttpComponent的org.apache.http.client.HttpClient創(chuàng)建WebClient,以便在異步操作中使用它。有關(guān)如何操作的任何想法
推薦答案
隨著Spring Framework5.3和Spring Boot2.4的發(fā)布,現(xiàn)在在ApacheHttpClient5.0和Spring WebClient之間有內(nèi)置集成。
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>
這篇關(guān)于如何從APACHE Http客戶端創(chuàng)建Spring WebClient的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,