Spring Cloud Feign 

简化RestTemplate调用形式

1. pom.xml

<!-- feign 声明式服务调用 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

2. application.yml

spring:
application:
name: feign-client server:
port: 8086

3. Application.java

@SpringBootApplication
@EnableFeignClients
public class FeginClientApplication { public static void main(String[] args) {
SpringApplication.run(FeginClientApplication.class, args);
} }

@EnableFeignClients 启动Feign客户端

4. Client.java

@Service
@FeignClient("hello-service")
public interface HelloServiceClient { @RequestMapping(method = RequestMethod.GET, value = "/hello")
String hi(); }
  • @FeignClient("hello-service") 指定注册服务的名字
  • /hello 服务请求地址

注意:

@RequestMapping(method = RequestMethod.GET, value = "/hello")
  1. 不能使用GetMapping
  2. 需通过value指定请求路径

访问: http://localhost:8086/feign/hi

Hello World!

Spring Cloud 2-Feign 声明式服务调用(三)的更多相关文章

  1. Spring Cloud Feign 声明式服务调用

    目录 一.Feign是什么? 二.Feign的快速搭建 三.Feign的几种姿态 参数绑定 继承特性 四.其他配置 Ribbon 配置 Hystrix 配置 一.Feign是什么? ​ 通过对前面Sp ...

  2. spring cloud 系列第4篇 —— feign 声明式服务调用 (F版本)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.feign 简介 在上一个用例中,我们使用ribbon+restTem ...

  3. Spring Cloud Feign声明式服务调用(转载)+遇到的问题

    转载:原文 总结: 1.pom添加依赖 2.application中填写正确的eureka配置 3.启动项中增加注解 @EnableFeignClients 4.填写正确的调用接口 通过原文使用Fei ...

  4. 笔记:Spring Cloud Feign 声明式服务调用

    在实际开发中,对于服务依赖的调用可能不止一处,往往一个接口会被多处调用,所以我们通常会针对各个微服务自行封装一些客户端类来包装这些依赖服务的调用,Spring Cloud Feign 在此基础上做了进 ...

  5. Feign声明式服务调用

    Feign是一种声明式.模板化的HTTP客户端(仅在Application Client中使用).声明式调用是指,就像调用本地方法一样调用远程方法,无需感知操作远程http请求. Spring Clo ...

  6. SpringCloud实战-Feign声明式服务调用

    在前面的文章中可以发现当我们通过RestTemplate调用其它服务的API时,所需要的参数须在请求的URL中进行拼接,如果参数少的话或许我们还可以忍受,一旦有多个参数的话,这时拼接请求字符串就会效率 ...

  7. SpringCloud无废话入门03:Feign声明式服务调用

    1.Feign概述 在上一篇的HelloService这个类中,我们有这样一行代码: return restTemplate.getForObject("http://hello-servi ...

  8. 第六章 声明式服务调用: Spring Cloud Feign

    我们在使用 Spring Cloud Ribbon 时, 通常都会利用它对 RestTemplate 的请求拦截来实现对依赖服务的接口调用, 而 RestTemplate 已经实现了对 HTTP 请求 ...

  9. 声明式服务调用:Spring Cloud Feign

    最近在学习Spring Cloud的知识,现将声明式服务调用:Spring Cloud Feign 的相关知识笔记整理如下.[采用 oneNote格式排版]

随机推荐

  1. 分布式 cephfs

    参考链接: http://docs.ceph.com/docs/mimic/cephfs/

  2. 【Codeforces 1000F】One Occurrence

    题意:给一个序列,每次查询某个区间内一个只出现一次的数. 思路:线段树. 首先我们看只出现一次的本质是什么. 如果一个数\(x​\)在\((l,r)​\)中只出现了一次,那么它在其中第一次出现位置为\ ...

  3. springBoot2.0+redis+fastJson+自定义注解实现方法上添加过期时间

    springBoot2.0集成redis实例 一.首先引入项目依赖的maven jar包,主要包括 spring-boot-starter-data-redis包,这个再springBoot2.0之前 ...

  4. Scrapy中选择器的用法

    官方文档:https://doc.scrapy.org/en/latest/topics/selectors.html Using selectors Constructing selectors R ...

  5. apply和call与this

    函数本身的apply方法,改变this指向哪个对象: function getAge() { var y = new Date().getFullYear(); return y - this.bir ...

  6. tomcat发请求,查看各个环节的耗时时间

    从一台机器给另一台机器tomcat发请求,查看各个环节的耗时时间 - 业精于勤,荒于嬉:行成于思,毁于随. - CSDN博客https://blog.csdn.net/YAOQINGGG/articl ...

  7. php函数 array_combine

    (PHP 5, PHP 7) array_combine — 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值 array_combine ( array $keys , array $ ...

  8. Activiti6事件及监听器配置(学习笔记)

    1.事件及监听器原理 当流程引擎启动的时候,我们定义的监听器,就已经注册在一个事件类型上面. 注册的方式有多种,它可以注册在所有的事件类型上面.也可以注册在指定的几个事件类型上面,这样引擎启动的时候就 ...

  9. 舵机&数据处理&stm32内存之堆栈溢出(遇到的问题)

    产品名称:TOWER PRO(辉盛)大扭力舵机MG996R (MG995升级产品)6v/11Kg厂家编号:MG996R产品净重: 55g产品尺寸: 40.7*19.7*42.9mm产品拉力: 9.4k ...

  10. git 原理

    1.git基本原理 2.git提交代码到远程仓库 3.远程仓库同步到本地 git pull #等同于下面命令 git fetch git merge 3.提交代码是冲突解决 一般提交前先get pul ...