RestTemplate实现远程调用
程序员文章站
2022-04-28 16:52:51
...
这里简单记录一下使用方法
1.配置类
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class ApplicationContextConfig {
@Bean
public RestTemplate getRestTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(5000);
requestFactory.setReadTimeout(3000);
return new RestTemplate(requestFactory);
}
}
2.测试
public class RestTemplateTest {
@Autowired
private RestTemplate restTemplate;
public static final String TDENGINE_URL = "http://192.168.1.144:8002";
@Test
public void test(String[] args) {
List<String> list = new ArrayList<String>();
list.add("123");
list.add("456");
//三个参数说明:1.请求地址 2.请求参数 3.相应数据类型
String postForObject = restTemplate.postForObject(TDENGINE_URL+"/save/", list, String.class);
}
上一篇: python怎么求最大值最小值
下一篇: RestTemplate远程调用