將pom.xml中關於spring-boot-start-web模塊的jar依賴去掉。web
錯誤分析:spring
根據上面描述(Description)中信息瞭解到GatewayAutoConfiguration這個配置中找不到ServerCodecConfig這個Bean。spring-boot
spring cloud gateway server項目是一個spring boot項目,在啓動的時候會去加載它的配置,其中有一個叫作GatewayClassPathWarningAutoConfiguration的配置類中有這麼一行代碼:this
@Configuration @ConditionalOnClass(name = "org.springframework.web.servlet.DispatcherServlet") protected static class SpringMvcFoundOnClasspathConfiguration { public SpringMvcFoundOnClasspathConfiguration() { log.warn(BORDER+"Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. "+ "Please remove spring-boot-starter-web dependency."+BORDER); } }
在類路徑上找到的Spring MVC,此時它與Spring Cloud網關不兼容。請刪除spring-boot-start-web依賴項。spa
由於spring cloud gateway是基於webflux的,若是非要web支持的話須要導入spring-boot-starter-webflux而不是spring-boot-start-web。server