首页 文章

可以将Spring Cloud Gateway应用程序作为 Cloud 配置服务器启用吗?

提问于
浏览
0

我正在尝试启用Spring Cloud Gateway应用程序,以便动态刷新其路由配置yml . 我已经能够设置 Cloud 配置服务器来托管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

但是,当尝试在我的Gateway的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 时,应用程序再次失败w /:

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

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

1 回答

  • 0

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

相关问题