Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestClient.Builder vs RestClientAutoConfiguration's Implementation #41568

Closed
miller79 opened this issue Jul 20, 2024 · 2 comments
Closed

RestClient.Builder vs RestClientAutoConfiguration's Implementation #41568

miller79 opened this issue Jul 20, 2024 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@miller79
Copy link

Everything below is looking at the code from Spring Boot 3.3.2

Looking at RestClientAutoConfiguration, the following code is used to create a RestClient.Builder:

	@Bean
	@Scope("prototype")
	@ConditionalOnMissingBean
	RestClient.Builder restClientBuilder(RestClientBuilderConfigurer restClientBuilderConfigurer) {
		RestClient.Builder builder = RestClient.builder()
			.requestFactory(ClientHttpRequestFactories.get(ClientHttpRequestFactorySettings.DEFAULTS));
		return restClientBuilderConfigurer.configure(builder);
	}

Comparing what the ClientHttpRequestFactories does compared to the default settings already in the RestClient, they seem very similar. The only difference I can tell is the Spring Boot ClientHttpRequestFactories looks for okhttp3.OkHttpClient while the DefaultRestClientBuilder looks for java.net.http.

I'm trying to find a good way to use the defaults provided by Spring Boot while doing custom enhancements outside of the service class itself so I can just inject the specific builder to match the practices I've used with RestTemplate, however with the additional code to initialize the builder, it seems either I'm missing something or this is something that shouldn't have been there in the first place and needs to be taken out. From what I can see, the autoconfig should be able to be something like the following but I'm also thinking maybe this was intentional for reasons that's not immediately apparent:

	@Bean
	@Scope("prototype")
	@ConditionalOnMissingBean
	RestClient.Builder restClientBuilder(RestClientBuilderConfigurer restClientBuilderConfigurer) {
		RestClient.Builder builder = RestClient.builder();
		return restClientBuilderConfigurer.configure(builder);
	}

Let me know your thoughts and if needed I can provide the approaches I had in mind and you can tell me if maybe my thought process was in the wrong place or not.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 20, 2024
@bclozel
Copy link
Member

bclozel commented Jul 21, 2024

This looks like a duplicate of #38856. Please advise.

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Jul 21, 2024
@miller79
Copy link
Author

You are correct. Thanks for the link. Closing this issue.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2024
@bclozel bclozel added status: duplicate A duplicate of another issue and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants