启动报错
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 Gateway 基于WebFlux(底层是采用Reactive Netty的NIO框架)框架实现的,与传统的SpringMvc分属两大体系,所以之间存在依赖冲突,我们只需要把SpringMvc模块使用exclusion移除掉即可。
在类路径上找到的Spring MVC,此时它与Spring Cloud网关不兼容。请删除spring-boot-start-web依赖项。
因为spring cloud gateway是基于webflux的,如果非要web支持的话需要导入spring-boot-starter-webflux而不是spring-boot-start-web。
注意有两种情况:
1、自身Moudle添加了spring-boot-start-web则直接删除即可
2、自身Moudle没有添加spring-boot-start-web,也没有继承Moudle,但是还是出现上面的错误,那就具体看看是不是继承了父Moudle下面的某个子Moudle,如果是也会将spring-boot-start-web继承过来的。
如果继承子Moudle,就用此方法进行排除
<dependency>
<groupId>com.slin.stu</groupId>
<artifactId>service-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency>