Cannot construct Spring webClient due to java.lang.IllegalStateException: No suitable default ClientHttpConnector found

Léo Schneider

I would like to use a specific WebClient in my service class. I get this exception while constructing it:

It looked like it was a dependency issue but a good old clean-install didn't change anything.

Do I need to specify manually a Bean in my configuration?

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.***.Client]: Constructor threw exception; nested exception is java.lang.IllegalStateException: No suitable default ClientHttpConnector found
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:213)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:310)
        ... 122 more
    Caused by: java.lang.IllegalStateException: No suitable default ClientHttpConnector found
        at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.getOrInitConnector(DefaultWebClientBuilder.java:266)
        at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:244)
        at com.***.Client.<init>(Client.kt:35)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:41)
        at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106)
        at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:152)
        at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
        at org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(BeanUtils.java:788)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:185)

My class is simply:

@Service
class Client {
    private val webClient = WebClient.builder()
            .baseUrl("https://****.com/")
            .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
            .build()
}

In my pom.xml file:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
        </dependency>
Léo Schneider

I found the problem: it turns out that netty dependencies were missing, as I imported the maven artifact that has WebClient but not the rest...

Replacing:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webflux</artifactId>
</dependency>

With:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

solved it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ElasticSearch SpringBoot+Spring Data: java.lang.IllegalStateException: No suitable constructor found on interface

Spring GlobalExceptionHandler : java.lang.IllegalStateException: Could not resolve parameter [0] ... No suitable resolver

java.lang.IllegalStateException: Could not evaluate condition owing to internal class not found. - Spring Boot + Spring Swagger

WebClient causes "java.lang.IllegalStateException: executor not accepting a task" in JUnit

Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'appController' bean method

Java.Lang.IllegalStateException Default FirebaseApp is not initialized

Spring batch using java annotations java.lang.IllegalStateException: Cannot create properties without meta data

Spring Data GemFire - Caused by: java.lang.IllegalStateException: The connection pool "DEFAULT" has not been created

"java.lang.IllegalStateException: Cannot load driver class" in Spring Boot application

Spring java.lang.IllegalStateException: Cannot create a session after the response has been committed

Spring boot : java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

Spring JPA Test java.lang.IllegalStateException

java.lang.IllegalStateException: No parser found for urn:security:1.1

java.lang.IllegalStateException: Required view not found - butterknife not working sometimes

Extracting a substring using Matcher: java.lang.IllegalStateException: No match found

java.lang.IllegalStateException: Required identifier property not found

java.lang.IllegalStateException: no matching editors or conversion strategy found

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process

Trouble with Spring async request processing in Controller - getting java.lang.IllegalStateException: Cannot forward after response has been committed

No default constructor found; nested exception is java.lang.NoSuchMethodException with Spring MVC?

Java no suitable constructor found

No suitable constructor found for java

java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout : XML

java.lang.IllegalStateException: Cannot read while there is an open stream writer

java.lang.IllegalStateException: Cannot find any build directories

java.lang.IllegalStateException: Ambiguous mapping. Cannot map method

java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction

Deal with java.lang.Errors in Spring's WebClient requests

spring boot cmd line cron expression java.lang.IllegalStateException