package com.ard.sample.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; @Configuration public class RestTemplateConfig { @Bean public RestTemplate restTemplate() { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); // 连接超时:10s factory.setConnectTimeout(10000); // 读取超时:5min(适配大文件上传/下载) factory.setReadTimeout(300000); // 开启流式请求,避免大文件加载到内存 factory.setBufferRequestBody(false); return new RestTemplate(factory); } }