restTemplate在springboot中没有初始化实例对象,不能直接使用,所以在使用前需要先进行实例化。
/**
* @description :RestConfig
* @author :liu
* @since :2021/6/10 10:06
*/
@Configuration
public class RestConfig {
/**
* 连接超时
*/
@Value("${resttemplate.connection.timeout}")
private int restTemplateConnectionTimeout;
/**
* 读取超时
*/
@Value("${resttemplate.read.timeout}")
private int restTemplateReadTimeout;
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory simleClientHttpRequestFactory){
RestTemplate restTemplate = new RestTemplateBuilder().build();
restTemplate.setRequestFactory(simleClientHttpRequestFactory);