This question already has answers here:
Custom RestTemplate using requestFactory of RestTemplateBuilder in SpringBoot 2.1.x is not backward compatible with version 1.5.x
(3个答案)
29天前关闭。
我的程序中有这段代码:
但是我有这个编译错误
即使该方法也期望这样:
和类
(3个答案)
29天前关闭。
我的程序中有这段代码:
this.restTemplate = restTemplateBuilder
.requestFactory(new HttpComponentsClientHttpRequestFactory());
但是我有这个编译错误
Cannot resolve method 'requestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory)'
即使该方法也期望这样:
public RestTemplateBuilder requestFactory(Class<? extends ClientHttpRequestFactory> requestFactory)
和类
HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean
最佳答案
试试这个
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
HttpClient httpClient = clientBuilder.build();
restTemplatebuilder.requestFactory(() -> { return new HttpComponentsClientHttpRequestFactory(httpClient);});
关于java - 使用SpringBoot 2.15在RestTemplateBuilder中进行类转换问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61951588/
10-11 04:57