【问题标题】:Can a Spring Cloud Gateway App be Enabled as a Cloud Config Server?可以将 Spring Cloud Gateway App 启用为 Cloud Config Server 吗?
【发布时间】:2019-03-02 19:03:54
【问题描述】:

我正在尝试启用 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

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

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。当尝试从 cloud-config-server 模块中排除 spring-boot-starter-web 时,应用程序再次失败:

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-cloud spring-cloud-config spring-cloud-gateway


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-06-18
      • 1970-01-01
      • 2015-08-28
      • 2017-06-23
      • 2019-06-24
      • 2017-02-06
      • 2016-02-18
      • 2018-02-09
      • 2015-04-07
      相关资源
      最近更新 更多