简体   繁体   English

HttpComponentsClientHttpConnector is not accepting org.apache.http.impl.nio.client.CloseableHttpAsyncClient for Webclient with Apache Http Client

[英]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.

相关问题 如何从 Apache Http Client 创建 Spring WebClient - How to create Spring WebClient from Apache Http Client SpringBoot 3 与 Spring Cloud Vault 3.1.1 运行时错误 java.lang.NoClassDefFoundError: org/apache/hc/client5/http/classic/HttpClient - SpringBoot 3 with Spring Cloud Vault 3.1.1 Runtime Error java.lang.NoClassDefFoundError: org/apache/hc/client5/http/classic/HttpClient Webflux Webclient - 将 HTTP2 请求作为客户端发送到启用 HTTP2 的服务器时出错 - Webflux Webclient - Error when sending HTTP2 requests as client to a HTTP2 enabled server Netty Http 客户端连接池 - Netty Http Client Connection Pool Micrometer Reactor Netty Http 客户端指标与 Http 客户端指标 - Micrometer Reactor Netty Http Client Metrics vs Http Client Metrics Webflux / Angular慢服务器端事件与http客户端 - Webflux/Angular slow Server side events vs http-client 使用 spring webclient 对 http 请求进行可读的调试日志记录 - Readable debug logging for http requests with spring webclient 如何确定 Spring WebClient 是否使用 HTTP/2? - How to determine if Spring WebClient is using HTTP/2? Spring MVC Servlet 与 WebClient 和 OAuth 客户端凭据 - Spring MVC Servlet with WebClient and OAuth Client Credentials 我们如何使用 Apache JMeter 模拟 webflux 客户端(反应式) - How can we simulate webflux client (reactive) using Apache JMeter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM