whycxzp
2025-03-26 427ec9e696494cedcde2d9c58e9565d1db6117aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.whyc.config;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
 
@Configuration
public class HttpConfig {
 
    @Bean
    @Scope("prototype")
    public RestTemplate getRestTemplate(){
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        // 设置连接超时时间(单位:毫秒)
        requestFactory.setConnectTimeout(5000);
        // 设置请求超时时间(单位:毫秒)
        requestFactory.setReadTimeout(10000);
        return new RestTemplate(requestFactory);
    }
 
}