spring-cloud - 可以将 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 MVC(servlets),网关基于spring webflux和Netty。它们不兼容,不能一起运行。
推荐阅读
- django - 如何在 Django rest API 检索视图中获取相关对象?
- git - Git local repository deleted when github project is deleted?
- vuetify.js - Vuetify - how to make sticky elements?
- amazon-web-services - 为什么使用 Terraform 解析我的 dynamo_db_table_name 时会出错?
- jmeter - 如何性能测试分析服务
- c++ - 从基于迭代器的 for 循环转换后,如何在 map::find() 中调用方法?
- python - Python 脚本依赖于另一个 .exe。是否可以将两者合并为一个.exe?
- c# - EF Core 3.0 存储过程:多个参数
- html - In a HTML email signature is there way to conditionally hide content?
- facebook-javascript-sdk - Fetch conversions with FB Marketing API