Spring Cloud全解析:服务调用之OpenFeign简介


文章目录


OpenFeign简介

OpenFeign是SpringCloud对于Feign进行的再次封装,使其支持了SpringMVC的标准注解以及HttpMessageConverters

依赖

xml 复制代码
<!-- openFeign -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

配置启动类

java 复制代码
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients   // 开启feign
public class ConsumerApp {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApp.class,args);
    }
}

feign接口编写

java 复制代码
@FeignClient(value = "SPRINGCLOUD2-PROVIDER")
public interface DeptClient {

    @GetMapping(value = "/dept/get/{id}")
    CommonResult<Dept> get(@PathVariable("id") long id);
}

直接调用该方法就可以调用该微服务的接口

参考文献

相关推荐
早点睡觉好了5 分钟前
JAVA中基本类型和包装类型的区别
java·开发语言
雅俗共赏zyyyyyy8 分钟前
SpringBoot集成配置文件加解密
java·spring boot·后端
计算机学姐16 分钟前
基于SpringBoot的送货上门系统【2026最新】
java·vue.js·spring boot·后端·mysql·spring·tomcat
码农水水19 分钟前
国家电网Java面试被问:二叉树的前序、中序、后序遍历
java·开发语言·面试
Yana.nice23 分钟前
JMS与JDBC
java
小湘西25 分钟前
Elasticsearch 的一些默认配置上下限
java·大数据·elasticsearch
算法与双吉汉堡33 分钟前
【短链接项目笔记】6 短链接跳转
java·开发语言·笔记·后端·springboot
独自破碎E38 分钟前
IDEA2023中新建Spring Boot2.X版本的工程的方法
java·spring boot·后端
醇氧42 分钟前
【idea】使用Live Templates
java·ide·intellij-idea
talenteddriver1 小时前
Java Web:http请求在springboot项目中的传递层级(自用笔记)
java·前端·spring boot·http