-
Notifications
You must be signed in to change notification settings - Fork 41.1k
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 Unit Test with @RestClientTest and MockRestServiceServer fails when using request factory JdkClientHttpRequestFactory #38832
Comments
I am having the same problem. The requestFactory(new JdkClientHttpRequestFactory()) method replaced the original MockClientHttpRequestFactory in the injected Mock RestClient.Builder. Here is a simple solution: just declare a bean to override the auto-configured RestClient.Builder. @Configuration
public class RestClientBuilderConfiguration {
@Bean
public RestClient.Builder restClientBuilder() {
return RestClient.builder()
.requestFactory(new JdkClientHttpRequestFactory());
}
} |
Thanks for trying the new You can work around this for now by using a @Bean
public RestClient restClient(RestClient.Builder builder) {
return builder.build();
}
@Bean
public RestClientCustomizer restClientCustomizer() {
return (restClientBuilder) -> restClientBuilder
.requestFactory(new JdkClientHttpRequestFactory())
.baseUrl(baseUrl);
} |
Thank you, Scott. It works for me. I would like to ask why not make JdkClientHttpRequestFactory the default request factory for autowired RestClient.Builder bean. In my case, the default SimpleClientHttpRequestFactory returns an empty response body. |
Thanks @Washingtonwei. I've created #38856 for us to take a look at the defaults for the Spring Boot auto-configuration. |
This doesn't look like specific to |
Hello, I have a very similar problem but from the other angle. I am trying to test timeouts and retries using Here's the example code:
And here is the setup of the
Is there a way I can test the delays and retries using this setup? |
I have not changed any default implementations, I have two API's, one for the same JSON placeholder, and another contacting another Spring Boot server running locally. |
Description
When creating RestClient Bean with JdkClientHttpRequestFactory, like below
Tests using
@RestClientTest
andMockRestServiceServer
fail to connect.Sample Application
https://github.com/williamsuane/failing-cat-fact/tree/master
Just execute the following test, as is
it blows with the following exception
By removing the
.requestFactory(new JdkClientHttpRequestFactory())
fromThe test works perfectly.
The text was updated successfully, but these errors were encountered: