1.定义 RestTemplateConfig 配置类

@Configuration
public class RestTemplateConfig
{

  @Bean
  public RestTemplate restTemplate(ClientHttpRequestFactory factory)
  {
    return new RestTemplate(factory);
  }

  @Bean
  public ClientHttpRequestFactory simpleClientHttpRequestFactory()
  {
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    factory.setReadTimeout(10000);//单位为ms
    factory.setConnectTimeout(10000);//单位为ms
    return factory;
  }
}

2.

@Autowired
private RestTemplate restTemplate;

3. 接口调用,数据解析
String url = zipKinUrl + "/zipkin/api/v1/traces?annotationQuery=&endTs="+currentTime
+"&limit=1000&lookback="+lookbackTime
+"&minDuration=&serviceName=twasp-gateway&sortOrder=duration-desc&spanName=all";

System.out.println("url = " + url);
//get json数据
JSONArray array = restTemplate.getForEntity(url, JSONArray.class).getBody();

 

springboot RestTemplate请求的更多相关文章

  1. 使用RestTemplate请求报出HttpClientErrorException异常并获取不到返回body数据

    描述: 使用RestTemplate请求url,由于Token等验证信息参数失效,报出 401 HttpClientErrorException异常.并且获取不到body消息体的错误信息.然而post ...

  2. Resttemplate请求失败如何获取返回的json

    参考:https://blog.csdn.net/u011974797/article/details/82424004 https://www.cnblogs.com/liumz0323/p/106 ...

  3. SpringBoot+RestTemplate 简单包装

        RestTemplate设计是为了Spring更好的请求并解析Restful风格的接口返回值而设计的,通过这个类可以在请求接口时直接解析对应的类.     在SpringBoot中对这个类进行 ...

  4. spring-boot RestTemplate 连接池

    以前我们项目都是基于Apache HttpClient 连接池进行web 接口调用,后来用spring-boot, 发现 RestTemplate 挺好用. 简单介绍下: 什么是RestTemplat ...

  5. RestTemplate 请求url

    1.get 请求 RestTemplate restTemplate = new RestTemplate(); String url = ""; JSONObject resul ...

  6. springboot RestTemplate httpclient

    RestTemplate是spring支持的一个请求http rest服务的模板对象,性质上有点像jdbcTemplate RestTemplate底层还是使用的httpclient(org.apac ...

  7. SpringBoot PUT请求

    (1)配置HiddenHttpMethodFilter(SpringMVC需要配置,SpringBoot已经为我们自动配置了) (2)在视图页面创建一个Post Form表单,在表单中创建一个inpu ...

  8. Springboot+RestTemplate 简单使用

        spring框架提供的RestTemplate类可用于在应用中调用rest服务,它简化了与http服务的通信方式,统一了RESTful的标准,封装了http链接, 我们只需要传入url及返回值 ...

  9. RestTemplate请求https忽略证书认证

    RestTemplate是Spring提供的用于访问Rest服务的客户端,提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率.RestTemplate 默认使用J2SE提供的方式( ...

随机推荐

  1. Atom插件安装及推荐

    简介(了解更多去google或baidu) Atom 代码编辑器支持 Windows.Mac.Linux 三大桌面平台,完全免费,并且已经在 GitHub 上开放了全部的源代码.在经过一段长时间的迭代 ...

  2. 性能测试 CentOS下结合InfluxDB及Grafana图表实时展示JMeter相关性能数据

    CentOS下结合InfluxDB及Grafana图表实时展示JMeter相关性能数据   by:授客 QQ:1033553122 实现功能 1 测试环境 1 环境搭建 2 1.安装influxdb ...

  3. C# 获取操作系统相关的信息

    本文通过一个Demo,讲解如何通过C#获取操作系统相关的信息,如内存大小,CPU大小,机器名,环境变量等操作系统软件.硬件相关信息,仅供学习分享使用,如有不足之处,还请指正. 涉及知识点: Envir ...

  4. C# 对象持久化

    本文以一个简单的小例子,简述对象持久化的相关知识,仅供学习分享使用,如有不足之处,还请指正. 概述 对象持久化是指将内存中的对象保存到可永久保存的存储设备中(如磁盘)的一种技术. 本文介绍的是除数据库 ...

  5. Android为TV端助力 事件分发机制

    android事件分发机制,给控件设置ontouch监听事件,当ontouch返回true时,他就不会走onTouchEvent方法,要想走onTouchEvent方法只需要返回ontouch返回fa ...

  6. python语言学习--2

    第三天1. python代码缩进规则:具有相同缩进的代码被视为代码块,4个空格, 不要使用Tab,更不要混合Tab和空格,否则很容易造成因为缩进引起的语法错误. 2.list:[...] 用(名称任意 ...

  7. (办公)重新选择一个开发工具Eclipse

    文章Eclipse内容摘抄自w3cschool的eclipse,原文地址:https://www.w3cschool.cn/eclipse/eclipse-run-configuration.html ...

  8. selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

    解决办法: 把chromedriver exe文件放到python scripts目录下

  9. linux安装教程

    一.安装准备工作 虚拟机VMWARE10 镜像文件CentOs6.5 二.安装过程 1.启动VMWARE10,点击创建新的虚拟机. 2.选择典型安装即可 3.这里我们选择稍后再进行安装操作系统,因为这 ...

  10. 在微信小程序中使用LeanCloud(一)

    之前学习了微信小程序前端,使用到LeanCloud线上数据库 [传送门].作为一个前端开发人员,了解后端及数据库是学习工作的需要. LeanCloud直接登录,未注册直接创建账户.它是一款免费的线上数 ...