question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use reactive WebClient without spring-boot-starter-reactor-netty

See original GitHub issue

This is probably more of a documentation issue but when developing a reactive application on Tomcat (and probably others) and you exclude starter-reactor-netty like this

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-reactor-netty</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>            
</dependency>

then WebClient won’t work. The class is on the path but creating a new one with return WebClient.create("http://localhost:8080"); will fail:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.reactive.function.client.WebClient]: Factory method 'webClient' threw exception; nested exception is java.lang.NoClassDefFoundError: reactor/ipc/netty/http/client/HttpClient
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:182)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:575)
	... 43 common frames omitted
Caused by: java.lang.NoClassDefFoundError: reactor/ipc/netty/http/client/HttpClient
	at org.springframework.http.client.reactive.ReactorClientHttpConnector.<init>(ReactorClientHttpConnector.java:47)
	at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.initExchangeFunction(DefaultWebClientBuilder.java:139)
	at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:115)
	at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:173)
	at com.example.demo.NewClass$CustomConfig.webClient(NewClass.java:29)
	at com.example.demo.NewClass$CustomConfig$$EnhancerBySpringCGLIB$$7b5a2896.CGLIB$webClient$0(<generated>)
	at com.example.demo.NewClass$CustomConfig$$EnhancerBySpringCGLIB$$7b5a2896$$FastClassBySpringCGLIB$$783fa80e.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:359)
	at com.example.demo.NewClass$CustomConfig$$EnhancerBySpringCGLIB$$7b5a2896.webClient(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:155)
	... 44 common frames omitted
Caused by: java.lang.ClassNotFoundException: reactor.ipc.netty.http.client.HttpClient
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
wilkinsonacommented, Mar 4, 2018

@dancingfrog You can set the web application type to none when creating your SpringApplication.

3reactions
madhtrcommented, Jul 23, 2021

@dancingfrog You can set the web application type to none when creating your SpringApplication.

True. But if I am creating a project intended to be used as a maven dependency in another project, the developer on the dependent project will have to do this as well.

Excluding spring-boot-starter-tomcat worked with spring boot web. But it does not work with webflux. This is not ideal IMHO.

Respectfully.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use reactive WebClient without spring-boot-starter ...
Unable to use reactive WebClient without spring-boot-starter-reactor-netty.
Read more >
How to use the Spring WebClient with Jetty, instead of Netty?
According to the documentation it is possible to use the Spring Reactive WebClient with a different server as Netty:.
Read more >
Web on Reactive Stack - Spring
A practical way to start without a full switch is to use the reactive WebClient . Beyond that, start small and measure the...
Read more >
Spring Boot Reactor Netty Configuration - Baeldung
In this tutorial, we're going to look at different configuration options for a Reactor Netty server in a Spring Boot application.
Read more >
Dealing with Spring's reactive WebClient - Kode Krunch
Dealing with Spring's reactive WebClient ... Unfortunately if you try to use any URL that is not on the Internet (for example an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found