RestTemplate设置超时时间

 HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
        httpRequestFactory.setConnectionRequestTimeout(10*1000);
        httpRequestFactory.setConnectTimeout(10*1000);
        httpRequestFactory.setReadTimeout(10*1000);
        httpRequestFactory.setBufferRequestBody(false);
        RestTemplate template = new RestTemplate(httpRequestFactory);
        ClientHttpRequestFactory clientFactory = new HttpComponentsClientHttpRequestFactory();
        template.setRequestFactory(clientFactory);
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
        @SuppressWarnings({ "rawtypes", "unchecked" })
        HttpEntity requestEntity = new HttpEntity("", requestHeaders);
        ResponseEntity> responseEntity = template.exchange(uri, HttpMethod.POST, requestEntity,
                new ParameterizedTypeReference>() {
                });

你可能感兴趣的:(RestTemplate设置超时时间)