From 718689b223adb0e642c6bf9e2fd03ece217812cc Mon Sep 17 00:00:00 2001 From: wangliwen Date: Fri, 11 Nov 2022 09:25:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80resttemp=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/renren/common/config/RestTemplateConfig.java | 10 ++++++++-- renren-admin/src/main/resources/application.yml | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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: