Broken ResourceController in Spring Cloud Config Server with SpringBoot reactive web app

103 Views Asked by At

I am trying to bring up spring cloud config server 4.1.0 in spring boot starter webflux 3.2.2 app.

Though EnvironmentController works fine but ResourceController under the hood still uses ServletWebRequest with GET API which no more works with reactive stack.

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

My question is whether spring cloud config server is meant to run only with Spring Web or am I missing some configuration to make ResourceController functional with spring webflux.

1

There are 1 best solutions below

0
VonC On BEST ANSWER

You have:

Client Request
       |
Spring Cloud Config Server
       | (ServletWebRequest)
ResourceController (Not Working)
       |
 Spring WebFlux (Reactive Stack)

As commented by [Yousha Aleayoub), the ResourceController in the Spring Cloud Config Server does not seem indeed compatible with Spring WebFlux, because it uses ServletWebRequest, which is designed for a servlet-based environment and not for the non-blocking, reactive programming model provided by WebFlux.

The Spring Cloud Config Server is primarily designed to work with the traditional servlet-based Spring Web (spring-webmvc) framework.

To integrate Spring Cloud Config Server into a reactive Spring Boot application, you might consider instead:

  • running the Config Server as a separate, standalone application using Spring MVC, and interact with it from your reactive applications. This is the simplest solution, and adheres to the microservices architecture principle of separation of concerns.

  • using a hybrid Spring application that supports both servlet and reactive stacks for different parts of the application, though this can lead to a more complex application setup and might not be ideal for all use cases.

  • implementing a custom version of the ResourceController or an equivalent mechanism within your Spring WebFlux application that fetches configuration data from the Config Server's Git backend or other storage directly, bypassing the need for the Config Server's servlet-based controllers. As a simplified example:

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