2

I am getting below exception while using 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;

Related JARS

enter image description here

This is a ANT based SPRING project. I dont get any compilation error.

This is the code where I am creating webClient

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 and sample URL are values I replaced. Looks like its some JAR issue but I have added almost all Jars that I found researching this error.

Thanks

1 Answer 1

3

It depends on the version Spring (and Reactor Netty). In version 5.2.x and later the class HttpClient extend ClientTransport - in this case your code will work. In earlier versions the documentation "offers" this implementation:

HttpClient httpClient = HttpClient.create().tcpConfiguration(client -> client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.