Преглед на файлове

[update] message:1.添加RestTemplateConfig配置类

kelei преди 10 месеца
родител
ревизия
5934b07feb
променени са 1 файла, в които са добавени 39 реда и са изтрити 0 реда
  1. 39 0
      admin/src/main/java/com/flyer/foster/config/RestTemplateConfig.java

+ 39 - 0
admin/src/main/java/com/flyer/foster/config/RestTemplateConfig.java

@@ -0,0 +1,39 @@
+package com.flyer.foster.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.http.client.ClientHttpRequestFactory;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+/**
+ * RestTemplateConfig
+ *
+ * @author kelei
+ * @since 2022/5/13/11:57
+ */
+@Configuration
+public class RestTemplateConfig {
+    @Bean
+    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
+        RestTemplate restTemplate = new RestTemplate(factory);
+        StringHttpMessageConverter stringConvert = new StringHttpMessageConverter(StandardCharsets.UTF_8);
+        stringConvert.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON));
+        restTemplate.getMessageConverters().add(stringConvert);
+        return new RestTemplate(factory);
+    }
+
+    @Bean
+    public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
+        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
+        // 单位ms
+        factory.setReadTimeout(150000);
+        factory.setConnectTimeout(150000);
+        return factory;
+    }
+}