package com.whyc.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; @Configuration public class HttpConfig { @Bean @Scope("prototype") public RestTemplate getRestTemplate(){ SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); // 设置连接超时时间(单位:毫秒) requestFactory.setConnectTimeout(5000); // 设置请求超时时间(单位:毫秒) requestFactory.setReadTimeout(10000); return new RestTemplate(requestFactory); } }