我正在try 在Spring Boot Starter WebFlux 3.2.2应用程序中调出SpringCloud配置服务器4.1.0.

虽然环境控制器工作得很好,但是资源控制器在幕后仍然使用带有Get API的ServletWebRequest,它不再与被动堆栈一起工作.

File: org.springframework.cloud.config.server.resource.ResourceController. 
method: @GettMapping({"/{name}/{profile}/{label}/**"})

我的问题是spring cloud config server是否意味着只能与Spring Web一起运行,或者我缺少一些配置来使ResourceController与spring webflux一起运行.

推荐答案

您必须:

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);
        }
    }
    

Java相关问答推荐

如何在Android上获取来电信息

在Java Stream上调用collect方法出现意外结果

使用@MappdSuperClass扩展ParentClass&Won t继承ParentClass属性

无法处理批处理侦听器中的反序列化异常

SpringBootreact 式Web应用程序的Spring Cloud Configer服务器中的资源控制器损坏

如何在Java中从XML中获取特定的 node ,然后将其删除?

第二次按下按钮后,我需要将按钮恢复到其原始状态,以便它可以再次工作

为什么Java编译器不区分不同类型的方法?

@Rollback @ Transmission在验收测试中不工作

使用Jolt将字段转换为列表

迁移到Java 17后,日期显示不准确

try 使用预准备语句占位符获取信息时出现Try-With-Resources错误

项目react 堆中doOnComplete()和Subscribe()的第三个参数之间的差异

Win32函数的JNA绑定DwmGetColorizationColor返回E_INVALIDARG错误

当使用不同的参数类型调用时,为什么围绕Objects.equals的类型安全包装不会失败?

为什么Spring要更改Java版本配置以及如何正确设置?

没有Google Play服务,Firebase Auth无法工作

spring 更新多项管理关系

Java方法参数:括号中的类型声明?

在输入端没有可行的替代方案'; Select *';