huang
2025-05-22 16b32f4511aa90b95b13a15751850cf6db0829e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.mes.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();
        factory.setConnectTimeout(5000);    // 连接超时5秒
        factory.setReadTimeout(5000);       // 读取超时5秒
        
        return new RestTemplate(factory);
    }