javaspringspring-boot

Dynamic url value in spring 6 httpexchanges


I am migrating my clients from Feign to spring 6 httpexchanges. With Feign it is possible to set the base url dynamically. However, I am not able to achieve this with httpexchanges. With httpexchanges an URI can be set. However, this will overwrite the whole path.

I've created the following client:

public interface MyClient {

    @GetExchange(value = "/some-path")
    String getData(URI baseUrl);
}

If I now call getData(URI.create("http://some-url.com") the resulting request is made to just http://some-url.com. Is it possible to call http://some-url.com/some-path?

I've also tried to set the base url as path variable

public interface MyClient {

    @GetExchange(value = "{baseUrl}/some-path")
    String getData(@PathVariable URI baseUrl);
}

However, this will encode my baseUrl and something like http%3A%2F%2Fsome-url.com%2Fsome-path is called.


Solution

  • This will be possible with Spring 6.1 (Spring Boot 3.2) https://github.com/spring-projects/spring-framework/issues/30935