欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

springboot集成springCloud中gateway时启动报错的解决

程序员文章站 2022-06-24 11:28:59
在项目中引入springcloud中的gateway时报以下错误description:parameter 0 of method modifyrequestbodygatewayfilterfact...

在项目中引入springcloud中的gateway时报以下错误

description:

parameter 0 of method modifyrequestbodygatewayfilterfactory in org.springframework.cloud.gateway.config.gatewayautoconfiguration
required a bean of type 'org.springframework.http.codec.servercodecconfigurer' that could not be found.

action:
consider defining a bean of type 'org.springframework.http.codec.servercodecconfigurer' in your configuration.

这个是由于依赖冲突,spring-cloud-starter-gateway与spring-boot-starter-web和spring-boot-starter-webflux依赖冲突

解决方式:

在引入gateway时过滤掉上面两个依赖

 <dependency>
            <groupid>org.springframework.cloud</groupid>
            <artifactid>spring-cloud-starter-gateway</artifactid>
            <exclusions>
                <exclusion>
                    <groupid>org.springframework.boot</groupid>
                    <artifactid>spring-boot-starter-web</artifactid>
                </exclusion>
                <exclusion>
                    <groupid>org.springframework.boot</groupid>
                    <artifactid>spring-boot-starter-webflux</artifactid>
                </exclusion>
            </exclusions>
        </dependency>

springboot整合gateway启动失败

问题:

springboot整合gateway启动失败

***************************
application failed to start
***************************
description:
an attempt was made to call a method that does not exist. the attempt was made from the following location:
org.springframework.cloud.gateway.config.gatewayautoconfiguration$nettyconfiguration.gatewayhttpclient(gatewayautoconfiguration.java:622)
the following method did not exist:
reactor.netty.resources.connectionprovider.elastic(ljava/lang/string;ljava/time/duration;ljava/time/duration;)lreactor/netty/resources/connectionprovider;
the method's class, reactor.netty.resources.connectionprovider, is available from the following locations:
jar:file:/c:/users/administrator/.m2/repository/io/projectreactor/netty/reactor-netty/0.9.1.release/reactor-netty-0.9.1.release.jar!/reactor/netty/resources/connectionprovider.class
it was loaded from the following location:
file:/c:/users/administrator/.m2/repository/io/projectreactor/netty/reactor-netty/0.9.1.release/reactor-netty-0.9.1.release.jar
action:
correct the classpath of your application so that it contains a single, compatible version of reactor.netty.resources.connectionprovider
disconnected from the target vm, address: '127.0.0.1:55875', transport: 'socket'
process finished with exit code 1

这块主要是版本兼容的问题,

最初用的版本是:

        <dependency>
            <groupid>io.projectreactor.netty</groupid>
            <artifactid>reactor-netty</artifactid>
            <version>0.9.4.release</version>
        </dependency>

网上有的是需要把这个版本降低,我这是降低了也不行

最后升高了版本改成了:

        <dependency>
            <groupid>io.projectreactor.netty</groupid>
            <artifactid>reactor-netty</artifactid>
            <version>0.9.14.release</version>
        </dependency>

本项目里springboot版本为:2.3.1,根据自己项目需要吧,看一下自己项目中各个版本之间的问题

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。