我正在尝试启用Spring Cloud Gateway应用程序来动态自动刷新其路由配置。我已经能够设置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与网关不兼容;网关是Netty应用程序,而spring-boot-starter-web使用tomcat/servlets。当尝试从云配置服务器模块中排除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 app不能作为CloudConfig服务器开通?还是我错过了什么。我的sprincCloudVersion是Finchley.SR1
发布于 2018-09-27 12:59:47
他们不能。配置服务器基于spring MVC (servlets),网关基于spring webflux和Netty。它们不兼容,不能一起运行。
https://stackoverflow.com/questions/52527260
复制相似问题