Skip to content

Conversation

@PandelisZ
Copy link

Problem

  • Properties under spring.http.client.restclient (for example apiversion.insert.header) were not being applied to RestClient instances, causing settings like X-Version not to be applied.

What I changed

  • Enabled configuration properties for the restclient module by adding @EnableConfigurationProperties(RestClientProperties.class) to RestClientAutoConfiguration.
  • Added RestClientProperties (extends HttpClientProperties) bound to spring.http.client.restclient so base-url, default headers and apiversion settings can be configured.
  • Injected RestClientProperties into RestClientBuilderConfigurer and applied its values when building a RestClient:
    • baseUrl -> builder.baseUrl
    • defaultHeader -> builder.defaultHeaders (merges headers)
    • apiversion.defaultVersion -> builder.defaultApiVersion
    • apiversion.insert -> builder.apiVersionInserter (via PropertiesApiVersionInserter)
  • Minor plumbing: added PropertyMapper usage and a helper to copy default headers into HttpHeaders.

Files changed

  • RestClientAutoConfiguration: enable properties and pass RestClientProperties to the configurer.
  • RestClientBuilderConfigurer: accept and apply RestClientProperties; use PropertyMapper to map values; add header merging and api-version inserter wiring.
  • RestClientProperties: new ConfigurationProperties class for spring.http.client.restclient.

Effect

  • Properties like spring.http.client.restclient.apiversion.insert.header=X-Version and spring.http.client.restclient.default-header.* will now be applied to RestClient instances.

Notes

  • The code guards against null properties and reuses existing defaults when properties are not provided.
  • No behavioral changes to customizers; they are still applied after properties.

This pull request was co-created with Cosine Genie

Original Task: spring-boot/y90vpvvwwjwp
Author: Pandelis Zembashis

… headers and api-version to RestClient.Builder

Co-authored-by: Genie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant