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);
}

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

参考文献

相关推荐
MaxHua几秒前
彻底搞懂Spring AOP:概念与实战
java·后端·架构
用户84913717547162 分钟前
实战复盘:10W+ QPS 秒杀架构演进(Redis Lua + 分片 + RabbitMQ)
java·架构·设计
b***9103 分钟前
idea创建springBoot的五种方式
java·spring boot·intellij-idea
BD_Marathon5 分钟前
【IDEA】常用快捷键【上】
java·ide·intellij-idea
BD_Marathon8 分钟前
【IDEA】工程与模块的管理
java·ide·intellij-idea
tgethe12 分钟前
MybatisPlus基础部分详解(中篇)
java·spring boot·mybatisplus
core51215 分钟前
【Java AI 新纪元】Spring AI 深度解析:让 Java 开发者无缝接入大模型
java·人工智能·spring·ai
Y***890815 分钟前
Spring Boot的项目结构
java·spring boot·后端
好好研究16 分钟前
MyBatis框架 - 注解形式
java·数据库·mysql·maven·mybatis
烤麻辣烫32 分钟前
黑马程序员苍穹外卖(新手)DAY8
java·开发语言·学习·spring·intellij-idea