diff --git a/renren-admin/src/main/java/io/renren/common/config/RestTemplateConfig.java b/renren-admin/src/main/java/io/renren/common/config/RestTemplateConfig.java index 685b4cea..5f4bdbb1 100644 --- a/renren-admin/src/main/java/io/renren/common/config/RestTemplateConfig.java +++ b/renren-admin/src/main/java/io/renren/common/config/RestTemplateConfig.java @@ -1,5 +1,6 @@ package io.renren.common.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.ClientHttpRequestFactory; @@ -12,6 +13,11 @@ import java.nio.charset.Charset; @Configuration public class RestTemplateConfig { + @Value("${rest_template.read_timeout}") + private Integer read_timeout; + @Value("${rest_template.connect_timeout}") + private Integer connect_timeout; + @Bean public RestTemplate restTemplate(ClientHttpRequestFactory factory) { RestTemplate restTemplate = new RestTemplate(factory); @@ -22,8 +28,8 @@ public class RestTemplateConfig { @Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory() { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); - factory.setReadTimeout(30 * 000);//单位为ms - factory.setConnectTimeout(5 * 1000);//单位为ms + factory.setReadTimeout(read_timeout);//单位为ms + factory.setConnectTimeout(connect_timeout);//单位为ms factory.setOutputStreaming(false); // InetSocketAddress socketAddress = new InetSocketAddress("192.168.124.31", 8888); diff --git a/renren-admin/src/main/resources/application.yml b/renren-admin/src/main/resources/application.yml index 956344ae..36c6353d 100644 --- a/renren-admin/src/main/resources/application.yml +++ b/renren-admin/src/main/resources/application.yml @@ -20,6 +20,10 @@ big_date: census: type: 应用资源,组件服务,基础设施,数据资源,知识库 applyType: 应用资源,业务组件,图层服务,开发组件,智能算法 +# 全局RestTemplate配置 +rest_template: + read_timeout: 30000 + connect_timeout: 5000 # 海信网关 hisense: gateway: