Gateway和spring-boot-starter-web冲突问题

Gateway和spring-boot-starter-web冲突问题

SpringCloud 版本 ---- Finchley.SR2
SpringBoot 版本 ---- 2.0.6.RELEASE

引入gateway 依赖启动网关子项目报错

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

启动网关报错

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-31 10:26:35.211 ERROR 13124 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

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.


Process finished with exit code 1

问题分析:
gateway构建与Spring 5+,基于Spring boot 2.x响应式的、非阻塞式的API,同时,他支持webSockets和spring框架紧密集成

报错原因:启动时默认使用了spring-boot-starter-web的内置容器,不支持非阻塞

问题解决:
有两种解决方法:

1、排除web内置容器

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- Maven整个生命周期内排除内置容器,排除内置容器导出成war包可以让外部容器运行spring-boot项目-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2、使用spring-webflux模块,webflux有一个全新的非阻塞的函数式Reactive Web框架,可以用来构建异步的、非阻塞的事件驱动服务

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值