gateway报错:ServerCodecConfigurer is that could not be found

系统管理员 2023-02-13 12:24 150阅读 0赞

gateway启动报错:

  1. org.springframework.cloud.gateway.config.GatewayAutoConfiguration required
  2. a bean of type 'org.springframework.http.codec.ServerCodecConfigurer'
  3. that could not be found

将pom.xml中关于spring-boot-start-web模块的jar依赖去掉。

错误分析:

根据上面描述(Description)中信息了解到GatewayAutoConfiguration这个配置中找不到ServerCodecConfig这个Bean。

spring cloud gateway server项目是一个spring boot项目,在启动的时候会去加载它的配置,其中有一个叫做GatewayClassPathWarningAutoConfiguration的配置类中有这么一行代码:

  1. @Configuration
  2. @ConditionalOnClass(name = "org.springframework.web.servlet.DispatcherServlet")
  3. protected static class SpringMvcFoundOnClasspathConfiguration {
  4. public SpringMvcFoundOnClasspathConfiguration() {
  5. log.warn(BORDER+"Spring MVC found on classpath, which is incompatible with Spring Cloud
  6. Gateway at this time. "+
  7. "Please remove spring-boot-starter-web dependency."+BORDER);
  8. }
  9. }

在类路径上找到的Spring MVC,此时它与Spring Cloud网关不兼容。请删除spring-boot-start-web依赖项。

因为spring cloud gateway是基于webflux的,如果非要web支持的话需要导入spring-boot-starter-webflux而不是spring-boot-start-web。

发表评论

表情:
评论列表 (有 0 条评论,150人围观)

还没有评论,来说两句吧...

相关阅读