Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 无法构造Spring webClient,因为java.lang.IllegalStateException:未找到合适的默认ClientHttpConnector_Spring Boot_Kotlin - Fatal编程技术网

Spring boot 无法构造Spring webClient,因为java.lang.IllegalStateException:未找到合适的默认ClientHttpConnector

Spring boot 无法构造Spring webClient,因为java.lang.IllegalStateException:未找到合适的默认ClientHttpConnector,spring-boot,kotlin,Spring Boot,Kotlin,我想在我的服务类中使用特定的WebClient。我在构造它时遇到此异常: 看起来这是一个依赖性问题,但是一个好的旧的干净安装并没有改变任何东西 我是否需要在配置中手动指定Bean Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.***.Client]: Constructor threw exception; nested exception is java.l

我想在我的服务类中使用特定的
WebClient
。我在构造它时遇到此异常:

看起来这是一个依赖性问题,但是一个好的旧的干净安装并没有改变任何东西

我是否需要在配置中手动指定Bean

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)
在我的
pom.xml
文件中:

<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>

org.springframework.boot
弹簧启动机tomcat
假如
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧靴启动器jdbc
org.springframework.boot
弹簧启动安全
org.springframework.boot
春季启动邮件
org.springframework.boot
弹簧启动装置
org.springframework.boot
弹簧起动试验
测试
org.springframework.boot
弹簧靴开发工具
真的
org.springframework.ws
SpringWS核心
org.springframework
春季网络流量

我发现了问题:结果是netty依赖项丢失了,因为我导入了maven工件,该工件具有
WebClient
,但其余的都没有

替换:

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

org.springframework
春季网络流量
与:


org.springframework.boot
弹簧启动器webflux

解决了它。

作为Léo Schenider答案的替代方案,您不需要用spring boot starter webflux替换spring webflux(添加了一些您不需要的附加依赖项),您只需要包括:

<dependency>
    <groupId>io.projectreactor.netty</groupId>
    <artifactId>reactor-netty-http</artifactId>
</dependency>

伊奥·内蒂
反应堆网络http

让spring webflux保持原样。

谢谢。我错过了spring boot starter webflux依赖项我已经添加了依赖项,如上所述,但meDid的问题仍然存在。你重新加载maven项目吗?这甚至修复了我在wildfly
io.projectreactor.netty:reactor netty
以及
org上的问题。springframework:spring webflux
依赖项对我有效。
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
    <groupId>io.projectreactor.netty</groupId>
    <artifactId>reactor-netty-http</artifactId>
</dependency>