【问题标题】:After upgrading spring-boot from 2.3.5.RELEASE to 2.4.0, ProxyProvider is not found in the package reactor.netty.tcpspring-boot从2.3.5.RELEASE升级到2.4.0后,包reactor.netty.tcp中找不到ProxyProvider
【发布时间】:2021-09-15 10:00:46
【问题描述】:

在 pom.xml 中从 Spring Boot 版本 2.3.5.RELEASE 升级到 2.4.0 后,无法再导入类 ProxyProvider (import reactor.netty.tcp.ProxyProvider;)。请注意,即使使用更高版本的 Spring Boot(尝试了 2.5.0 和 2.5.2)它也不起作用。 通过检查 Maven 依赖项,我注意到:

  • 在 2.3.5.RELEASE 版本中,该类取自 io.projectreactor.netty:reactor-netty:0.9.12.RELEASE
  • 在 2.4.0 版本中,该类取自 io.projectreactor.netty:reactor-netty-http:1.0.1

我可以通过检查导入的类 reactor.netty.http.client.HttpClient 的来源来找到有关 IntelliJ 的信息,尽管来自上述两个不同的库,但它适用于两个版本。

您知道如何解决从 Spring Boot 2.4.0 开始的编译问题吗?

请注意,我在 Spring Boot 的问题跟踪器中发现了相同的问题,但不幸的是它已关闭,没有给出任何解释:https://github.com/spring-projects/spring-boot/issues/24414

作为进一步的信息,这些是 2.3.5.RELEASE 情况下的所有 Netty 依赖项:

这些当 Spring Boot 版本是 2.4.0 时:

还请注意,在 pom.xml 中,我在两种情况下都导入了 2.3.5 版的依赖项 azure-keyvault-secrets-spring-boot-starter(但即使使用已移至该库的最新版本,它也会出现相同的问题https://mvnrepository.com/artifact/com.azure.spring/azure-spring-boot-starter-keyvault-secrets/3.6.0) :

<!-- Azure KeyVault access (password safe) -->
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
    <version>${azure.version}</version>
    <scope>runtime</scope>
</dependency>

这是使用 ProxyProvider 类的代码:

HttpClient httpClient = HttpClient.create()
    .tcpConfiguration(tcpClient -> (sslContext != null
            ? tcpClient.secure(sslProviderBuilder -> sslProviderBuilder.sslContext(sslContext))
            : tcpClient)
            .proxy(proxy -> proxy
                    .type(ProxyProvider.Proxy.HTTP)
                    .host(host)
                    .port(port))
    );

【问题讨论】:

    标签: java spring-boot maven netty reactor-netty


    【解决方案1】:

    我注意到,在我的代码中,tcpConfiguration 方法在 Spring Boot 版本 2.4.0 上已被弃用,从而找到了解决方案。然后我尝试寻找替代方案,从 Github 的这篇文章中,我找到了关于如何改进代码的提示:https://github.com/reactor/reactor-netty/issues/1397#issuecomment-751976453。简而言之,它说

    您可以通过 HttpClient.tcpConfiguration() 配置的所有内容,现在您可以直接使用 HttpClient 公开的方法进行配置

    对于任何感兴趣的人,我在这里发布我更新的代码,它与问题中的代码具有相同的逻辑,但没有错误,在 Spring Boot 2.4.0 中:

    HttpClient httpClient = HttpClient.create();
                if (sslContext != null) {
                    httpClient = httpClient.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
                }
                httpClient = httpClient.proxy(typeSpec -> typeSpec.type(ProxyProvider.Proxy.HTTP).host(host).port(port));
    

    在这种情况下,仍然使用 ProxyProvider 类,但它来自不同的包:reactor.netty.transport.ProxyProvider(而不是 reactor.netty.tcp.ProxyProvider)。

    【讨论】:

    猜你喜欢
    • 2021-03-08
    • 2021-03-02
    • 1970-01-01
    • 2021-04-05
    • 2023-04-07
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    相关资源
    最近更新 更多