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. Mac中安装git后,终端运行git出错,提示安装Xcode

    mac用户不使用Xcode安装git之后,默认安装路径是: /usr/local/git 但是在终端运行 git 命令时候的路径是: /usr/bin/git 当我们输入 git 命令时出现如下错误, ...

  2. NOIP2018:The First Step

    NOIP2018 RP=Ackermann(4,3) Day 0 日常不想做题也不知道要写什么qwq Day 1 接到$smy$巨佬的催更私信于是来更了(原本准备咕掉的) 最开始的策略是准备总览题目, ...

  3. UOJ188 Sanrd Min_25筛

    传送门 省选之前做数论题会不会有Debuff啊 这道题显然是要求\(1\)到\(x\)中所有数第二大质因子的大小之和,如果不存在第二大质因子就是\(0\) 线性筛似乎可以做,但是\(10^{11}\) ...

  4. jenkins部署net core初探

    一步一步,小心翼翼吖.看了好几个博客,摸索了两天了,才搭建成功,不容易,先写篇文章记下来,hhhhhhhhhhhh 相关环境配置 服务器:centos7 源代码管理器:git 技术选型:net cor ...

  5. SpringBoot使用Filter过滤器处理是否登录的过滤时,用response.sendRedirect()转发报错

    1.使用response.sendRedirect("/login")时报错,控制台报错如下: Cannot call sendError() after the response ...

  6. Python基础知识5-递归函数、生成器

    函数执行流程* 递归Recursion 递归的性能  递归总结 递归练习: def fac(n): if n==1: return n return n*fac(n-1) def fac1(n, f= ...

  7. Unable to preventDefault inside passive event listener

    最近做项目经常在 chrome 的控制台看到如下提示: Unable to preventDefault inside passive event listener due to target bei ...

  8. Python——字符格式化

    一.分类:%格式符方式,format方式 二.%格式符 1.%s——字符占位,%d——数字占位(十进制) a = ("%(name)s--%(age)d" % {'name':'x ...

  9. 前端基础之BOM和DOM(响应式布局、计时器、搜索框、select联动)

    一.BOM和DOM JavaScript分为 ECMAScript,DOM,BOM. BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进 ...

  10. 解决win10隔几分钟自动黑屏睡眠的方法

    来源:win10总是很快自动休眠怎么解决? - 风格不空格的回答 - 知乎 https://www.zhihu.com/question/39263412/answer/87430653 1.运行注册 ...