Xiajijian
2026-03-16 0ab71d4f9154dc2a0306ea57ec08659f4e28e449
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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);
    }
}