首页 > 解决方案 > 可以将 Spring Cloud Gateway App 启用为 Cloud Config Server 吗?

问题描述

我正在尝试启用 Spring Cloud Gateway 应用程序以即时自动刷新其路由配置 yml。我已经能够设置一个 Cloud Config 服务器来托管 YAML 路由,并启用 Spring Cloud Gateway 通过@Scheduled contextRefresher.refresh()使用来自动刷新其配置。但是,这需要两个正在运行的应用程序,我们希望尽量减少支持此要求所需的额外服务器数量。

Spring Cloud Config Server 文档建议任何启动应用程序都可以通过@EnableConfigServer注释嵌入配置服务器:https ://cloud.spring.io/spring-cloud-static/spring-cloud.html#_spring_cloud_config_server

但是,当尝试spring-cloud-config-server在网关的 build.gradle 中引入模块时,我在启动时遇到以下错误:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.http.codec.ServerCodecConfigurer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

从这里的讨论(https://github.com/spring-cloud/spring-cloud-gateway/issues/319)看来,出现上述问题是因为 spring-boot-starter-web 与网关不兼容;Gateway 是一个 Netty 应用程序,spring-boot-starter-web 使用 tomcat/servlets。尝试spring-boot-starter-web从 cloud-config-server 模块中排除时,应用程序再次失败,原因如下:

onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/web/servlet/config/annotation/WebMvcConfigurerAdapter.class] cannot be opened because it does not exist

是否无法将 Spring Cloud Gateway 应用程序启用为 CloudConfig 服务器?或者我错过了什么。FWIW 我的 sprincCloudVersion 是Finchley.SR1

标签: spring-cloudspring-cloud-configspring-cloud-gateway

解决方案


他们不能。配置服务器基于spring MVC(servlets),网关基于spring webflux和Netty。它们不兼容,不能一起运行。


推荐阅读