您必须:
Client Request
|
Spring Cloud Config Server
| (ServletWebRequest)
ResourceController (Not Working)
|
Spring WebFlux (Reactive Stack)
正如[Yousha Aleayoub]的commented,Spring Cloud Configer Server中的ResourceController
似乎并不真正与Spring WebFlux兼容,因为它uses ServletWebRequest
是为基于Servlet的环境而设计的,而不是为WebFlux提供的非阻塞、react 式编程模型而设计的.
Spring Cloud Configer服务器主要设计用于与传统的基于Servlet的Spring Web (spring-webmvc) framework协同工作.
要将Spring Cloud Config Server集成到响应式Spring Boot应用程序中,您可以考虑:
使用Spring MVC将ConfigServer作为单独的独立应用程序运行,并从您的react 式应用程序与其交互.这是最简单的解决方案,并且遵循关注分离的微服务体系 struct 原则.
为应用程序的不同部分使用既支持Servlet又支持react 式堆栈的混合Spring应用程序,尽管这可能会导致更复杂的应用程序设置,并且可能不适用于所有用例.
在Spring WebFlux应用程序中实现ResourceController
的自定义版本或等效机制,直接从Config Server的Git后端或其他存储中获取配置数据,绕过对Config Server基于servlet的控制器的需要.举一个简单的例子:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
public class CustomConfigController {
@GetMapping("/{name}/{profile}/{label}/**")
public Mono<String> getConfigFile(@PathVariable String name, @PathVariable String profile, @PathVariable String label) {
// Implement fetching logic here, e.g., using WebClient to fetch configuration from a Git repository
return Mono.just("Configuration data for " + name + " with profile " + profile + " and label " + label);
}
}