23 lines
737 B
Java
23 lines
737 B
Java
|
|
package com.klp.config;
|
||
|
|
|
||
|
|
import org.springframework.context.annotation.Bean;
|
||
|
|
import org.springframework.context.annotation.Configuration;
|
||
|
|
import org.springframework.http.client.ClientHttpRequestFactory;
|
||
|
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||
|
|
import org.springframework.web.client.RestTemplate;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* RestTemplate配置类
|
||
|
|
*/
|
||
|
|
@Configuration
|
||
|
|
public class RestTemplateConfig {
|
||
|
|
|
||
|
|
@Bean
|
||
|
|
public RestTemplate restTemplate() {
|
||
|
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||
|
|
factory.setConnectTimeout(30000); // 30秒连接超时
|
||
|
|
factory.setReadTimeout(60000); // 60秒读取超时
|
||
|
|
|
||
|
|
return new RestTemplate(factory);
|
||
|
|
}
|
||
|
|
}
|