我的这段代码在使用的项目上运行良好RestTemplateBuilder 1.5.14
this.restTemplate = restTemplateBuilder
.setConnectTimeout(connectTimeout)
.setReadTimeout(readTimeout)
.requestFactory(new MyHttpComponentFactoryBuilder()
.build())
.build();
更新到 RestTemplateBuilder 2.1.5
我有这段代码后:
this.restTemplate = restTemplateBuilder
.setConnectTimeout(Duration.ofMillis(connectTimeout))
.setReadTimeout(Duration.ofMillis(readTimeout))
.requestFactory(new MyHttpComponentFactoryBuilder().build().getClass())
.build();
但是在运行代码时,我有一个 InvocationTargetException / NullPointerException
在删除行时消失了.requestFactory(new MyHttpComponentFactoryBuilder().build().getClass())
,但调试new MyHttpComponentFactoryBuilder().build().getClass()
不为空
我还尝试了提出的解决方案:
...
.requestFactory(new MyRequestFactorySupplier())
...
class MyRequestFactorySupplier implements Supplier<ClientHttpRequestFactory> {
@Override
public ClientHttpRequestFactory get() {
// Using Apache HTTP client.
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
HttpClient httpClient = clientBuilder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
requestFactory.setBufferRequestBody(false); // When sending large amounts of data via POST or PUT, it is recommended to change this property to false, so as not to run out of memory.
return requestFactory;
}
}
但我也有一个InvocationTargetException / NullPointerException