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. Hibernate入门(七)一对多入门案例

    一对多 场景模拟:用户(一)对订单(多) 1.建表 创建客户表,字段有:客户id,客户姓名,客户性别,客户年龄,客户年纪,客户电话. 创建订单表,字段有:订单编号,明细编号,客户编号(外键) DROP ...

  2. C#两个时间相减

    原文地址:http://www.jb51.net/article/60177.htm using System; using System.Collections.Generic; using Sys ...

  3. js 格式化数字(每三位加逗号)

    // 方法一 unction toThousands(num) { var result = [ ], counter = 0; num = (num || 0).toString().split(' ...

  4. 详解LSTM

    https://blog.csdn.net/class_brick/article/details/79311148 今天的内容有: LSTM 思路 LSTM 的前向计算 LSTM 的反向传播 关于调 ...

  5. Android 源码编译之旅

    目录 前言 背景 安装软件 正文 Mac 分区 移动硬盘分区 Repo 下载源码 编译 源码导入 Android Studio 查看 碰到的问题 Could not find a supported ...

  6. (办公)Mysql入门

    数据库的操作:1.用 SHOW 显示已有的数据库show databases 2.创建数据库:create database 创建数据库create database db_name3.删除数据库:d ...

  7. The server principal "sa" is not able to access the database "xxxx" under the current security context

    在SQL Server服务器上一个作业执行时,遇到下面错误信息: Message: Executed as user: dbo. The server principal "sa" ...

  8. Add correct host key in /root/.ssh/known_hosts to get rid of this message

    bug: Add correct host key in /root/.ssh/known_hosts to get rid of this message 解决办法: rm ~/.ssh/known ...

  9. [20190211]简单测试端口是否打开.txt

    [20190211]简单测试端口是否打开.txt --//昨天看一个链接,提到如果判断一个端口是否打开可以简单执行如下:--//参考链接:https://dba010.com/2019/02/04/c ...

  10. SQL语句计算距离今天生日还差几天

    转载于:http://www.w3dev.cn/article/20110125/sql-compute-birthdate-now-days.aspx SQL语句计算距离生日还差几天原理很简单,将要 ...