p-honggang.li
5 天以前 ac918503bb5e8fad007348e7e39ba7275b75f334
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.webmanage.config;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
 
/**
 * RestTemplate配置类
 */
@Configuration
public class RestTemplateConfig {
 
    @Autowired
    private WorkflowProperties workflowProperties;
 
    @Bean
    public RestTemplate restTemplate() {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        
        // 设置连接超时时间
        factory.setConnectTimeout(workflowProperties.getRestTemplate().getConnectTimeout());
        
        // 设置读取超时时间
        factory.setReadTimeout(workflowProperties.getRestTemplate().getReadTimeout());
        
        return new RestTemplate(factory);
    }
}