@Bean使用
作者:互联网
Spring配置类注解@Bean
用在方法上,生命当前方法返回值为bean,替代xml
@Bean(name = "httpsTemplate")
public RestTemplate httpsRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(getHttpClient());
requestFactory.setConnectTimeout(60000);
requestFactory.setReadTimeout(60000);
RestTemplate restTemplate = new RestTemplate(requestFactory);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ResourceHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
restTemplate.setMessageConverters(converters);
return restTemplate;
}
标签:restTemplate,RestTemplate,converters,Bean,使用,new,requestFactory 来源: https://blog.csdn.net/weixin_43600910/article/details/112728061