| | |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.client.SimpleClientHttpRequestFactory; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | /** |
| | | * @author xp |
| | | * @date 2022/11/16 |
| | | * 设置RestTemplate超时时间,单位:毫秒 |
| | | * 如这里设置为5s |
| | | */ |
| | | @Configuration |
| | | public class RestTemplateConfig { |
| | | |
| | | @Bean |
| | | public RestTemplate restTemplate() { |
| | | return new RestTemplate(); |
| | | SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| | | requestFactory.setConnectTimeout(1000 * 5); |
| | | requestFactory.setReadTimeout(1000 * 5); |
| | | return new RestTemplate(requestFactory); |
| | | } |
| | | |
| | | } |