设计模式:构建者模式
package cn.tju.edu.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestConfig {
@Bean
@LoadBalanced
public RestTemplate getRestTemplate(){
RestTemplateBuilder restTemplateBuilder=new RestTemplateBuilder();
restTemplateBuilder.setConnectTimeout(3000);
restTemplateBuilder.setReadTimeout(5000);
RestTemplate restTemplate=restTemplateBuilder.build();
return restTemplate;
}
}