美文网首页
resttemplate配置

resttemplate配置

作者: wangpeng123 | 来源:发表于2018-05-23 18:41 被阅读0次
        public ClientHttpRequestFactory httpRequestFactory() {
            return new HttpComponentsClientHttpRequestFactory(httpClient());
        }
    
        @Bean
        public RestTemplate restTemplate() {
            return new RestTemplate(httpRequestFactory());
        }
    
        @Bean
        public HttpClient httpClient() {
            Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("https", SSLConnectionSocketFactory.getSocketFactory())
                    .build();
            PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
            connectionManager.setMaxTotal(300);
            connectionManager.setDefaultMaxPerRoute(100);
    
            RequestConfig requestConfig = RequestConfig.custom()
                    .setSocketTimeout(8000)
                    .setConnectTimeout(8000)
                    .setConnectionRequestTimeout(8000)
                    .build();
    
            return HttpClientBuilder.create()
                    .setDefaultRequestConfig(requestConfig)
                    .setConnectionManager(connectionManager)
                    .build();
        }
    

    相关文章

      网友评论

          本文标题:resttemplate配置

          本文链接:https://www.haomeiwen.com/subject/hdkdjftx.html