提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
springboot项目编写RestTemplate配置类
代码
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
return new RestTemplate(factory);
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(15000);
factory.setReadTimeout(5000);
return factory;
}
}
引用
@Autowired
private RestTemplate restTemplate;
this.restTemplate.getForEntity(url, JSONObject.class);
总结
springboot项目编写RestTemplate配置类