huang
2025-05-20 e5b578d2c586ca9f664e31d3759952752255fdd3
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);
    }