14.springboot使用template调用服务api
来源:互联网 发布:java无参返回值 编辑:程序博客网 时间:2024/05/16 19:10
1.介绍
springboot调用服务api就是使用template操作类直接调用即可
2.建立工程
直接注入RestTemplate,使用它的方法来调用,在springcloud中还可以使用它进行远程调用
(1)app
package com.tyf.restTemplate;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.web.client.RestTemplateBuilder;import org.springframework.context.annotation.Bean;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.client.RestTemplate;@SpringBootApplication@RestController@RequestMapping("/template")public class App { public static void main( String[] args ) throws Exception{ SpringApplication.run(App.class, args); } @Bean//注入restApi的操作类 public RestTemplate restTemplate(RestTemplateBuilder builder) { restTemplate = builder.build(); return restTemplate; } private RestTemplate restTemplate; @RequestMapping(value="/test",method=RequestMethod.GET) public String test(){ //直接调用服务,返回数据 String data = restTemplate.getForObject( "http://gturnquist-quoters.cfapps.io/api/random", String.class); return data; } }
阅读全文
0 0
- 14.springboot使用template调用服务api
- springboot使用feign访问api
- 使用SpringBoot开发REST服务
- 使用ajax跨域调用springboot框架的api传输文件
- SpringBoot使用FeignClient进行服务间的调用,传递headers信息
- Solr6.6的安装以及Java使用SolrJ调用Solr服务,springmvc使用solr,springboot使用solr
- 如何使用Spring Cloud – 简单服务流程(服务发现与API调用)
- 如何使用Spring Cloud – 简单服务流程(服务发现与API调用)
- ui-router使用路由调用绝对路径template
- 使用Django REST Framework来快速实现API调用服务——下篇(编写API服务)
- 使用Springboot和Hystrix构建API Gateway
- springboot中使用swagger2管理测试api
- 8.springboot使用RestDoc创建api文档
- springboot中用RestTemplate调用百度ip定位服务
- SpringCloud(一):用springboot实现简单服务调用
- SpringBoot 中文手册 --Part IV --33 调用REST服务
- 使用SpringBoot进行远程RMI调用
- SpringBoot 模板引擎 Template engines
- CF#450 D.Unusual Sequences
- 2017年12月14日 16:54:19
- 关于我对于写博客写文章的理解
- redis命令--http://redisdoc.com/
- 批量图片增强工具
- 14.springboot使用template调用服务api
- 2017.12.14日记
- Redis集群搭建(3主3从)
- C# 数组动态添加新元素的 方法
- 【Maven学习】Nexus私服代理其他第三方的Maven仓库
- 月历
- 刷好墙面如何避免施工问题
- poj 3253(贪心 + 优先队列)
- Bentley.CivilStorm/SewerGEMS/StormCAD/GeomCaliper