[英]HttpComponentsClientHttpConnector is not accepting org.apache.http.impl.nio.client.CloseableHttpAsyncClient for Webclient with Apache Http Client
Im trying to run Webflux on Tomcat and try to create Sping WebClient with Apache Http Client.我试图在 Tomcat 上运行 Webflux 并尝试使用 Apache Http 客户端创建 Sping WebClient。
Reference Documentation stated that theres built-in support: https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-client-builder-http-components参考文档指出有内置支持: https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-client-builder-http-components
private ClientHttpConnector getApacheHttpClient(){
HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
clientBuilder.setDefaultRequestConfig(RequestConfig.DEFAULT);
CloseableHttpAsyncClient client = clientBuilder.build();
ClientHttpConnector connector = new HttpComponentsClientHttpConnector(client);
return connector;
}
But Springs HttpComponentsClientHttpConnector is not accepting org.apache.http.impl.nio.client.CloseableHttpAsyncClient.但是 Springs HttpComponentsClientHttpConnector 不接受 org.apache.http.impl.nio.client.CloseableHttpAsyncClient。 It requires org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.它需要 org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient。 So there seems to be a package rename and I can´t find a Maven Dependency that has the required class.所以似乎有一个 package 重命名,我找不到具有所需 class 的 Maven 依赖项。 Does anybody know the right Maven Dependency for that class.有谁知道 class 的正确 Maven 依赖关系。 Or how could I make it work?或者我怎样才能让它工作?
Apache HTTP Client 5 is a separate artifact. Apache HTTP 客户端 5 是单独的工件。 You'll need to add the following dependencies to your pom.xml
:您需要将以下依赖项添加到您的pom.xml
:
<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>
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector;
public class ApacheHttp {
public static void main(String[] args) {
new HttpComponentsClientHttpConnector(HttpAsyncClients.custom().build())
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.