Java NoSuchMethodError:基于ANT的Spring项目中的reactor.netty.http.client.HttpClient.option

Java NoSuchMethodError:基于ANT的Spring项目中的reactor.netty.http.client.HttpClient.option,java,spring,spring-boot,ant,webclient,Java,Spring,Spring Boot,Ant,Webclient,我在使用webClient时遇到以下异常 Failed to instantiate [org.springframework.web.reactive.function.client.WebClient]: Factory method 'webClient' threw exception; nested exception is java.lang.NoSuchMethodError: reactor.netty.http.client.HttpClient.option(Lio/nett

我在使用webClient时遇到以下异常

Failed to instantiate [org.springframework.web.reactive.function.client.WebClient]: Factory method 'webClient' threw exception; nested exception is java.lang.NoSuchMethodError: reactor.netty.http.client.HttpClient.option(Lio/netty/channel/ChannelOption;Ljava/lang/Object;)Lreactor/netty/transport/Transport;
WebClient webClient(ReactiveClientRegistrationRepository  clientRegistrations ) {
    
    HttpClient httpClient = HttpClient.create()
              .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
              .responseTimeout(Duration.ofMillis(5000))
              .doOnConnected(conn -> 
                conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS))
                  .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)));
    
    ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);

    InMemoryReactiveOAuth2AuthorizedClientService authorisedClient=new InMemoryReactiveOAuth2AuthorizedClientService(clientRegistrations);
    
    ServerOAuth2AuthorizedClientExchangeFilterFunction oauth=new ServerOAuth2AuthorizedClientExchangeFilterFunction(new AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(clientRegistrations,authorisedClient));
    oauth.setDefaultClientRegistrationId("id");
    return WebClient.builder().baseUrl("sample URL")
            .clientConnector(connector)
            .filter(oauth)
            .build();
}
相关罐子

这是一个基于ANT的SPRING项目。 我没有得到任何编译错误

这是我创建webClient的代码

Failed to instantiate [org.springframework.web.reactive.function.client.WebClient]: Factory method 'webClient' threw exception; nested exception is java.lang.NoSuchMethodError: reactor.netty.http.client.HttpClient.option(Lio/netty/channel/ChannelOption;Ljava/lang/Object;)Lreactor/netty/transport/Transport;
WebClient webClient(ReactiveClientRegistrationRepository  clientRegistrations ) {
    
    HttpClient httpClient = HttpClient.create()
              .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
              .responseTimeout(Duration.ofMillis(5000))
              .doOnConnected(conn -> 
                conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS))
                  .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)));
    
    ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);

    InMemoryReactiveOAuth2AuthorizedClientService authorisedClient=new InMemoryReactiveOAuth2AuthorizedClientService(clientRegistrations);
    
    ServerOAuth2AuthorizedClientExchangeFilterFunction oauth=new ServerOAuth2AuthorizedClientExchangeFilterFunction(new AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(clientRegistrations,authorisedClient));
    oauth.setDefaultClientRegistrationId("id");
    return WebClient.builder().baseUrl("sample URL")
            .clientConnector(connector)
            .filter(oauth)
            .build();
}
id和示例URL是我替换的值。 看起来这是个JAR问题,但我已经添加了我在研究这个错误时发现的几乎所有JAR


谢谢

这取决于Spring的版本(以及Reactor Netty)。 在版本5.2.x和更高版本中,类HttpClient extend ClientTransport-在这种情况下,代码将正常工作。 在早期版本中,“提供”此实现:

HttpClient httpClient = HttpClient.create().tcpConfiguration(client -> client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000))