Salmon的全栈知识 Salmon的全栈知识
首页
  • JavaSE
  • JavaWeb
  • Spring生态
  • JUC
  • JVM
  • Netty
  • Java各版本特性
  • 23种设计模式
  • Maven
  • Java常用框架
  • Dubbo
  • OpenFeign
  • Nacos
  • Zookeeper
  • Sentinel
  • Seata
  • SpringCloud Gateway
  • Apollo
  • Eureka
  • Go基础
  • Gin
  • SQL数据库

    • MySQL
    • Oracle
  • NoSQL数据库

    • Redis
    • MongoDB
    • ElasticSearch
  • 消息中间件

    • RabbitMQ
    • RocketMQ
    • Kafka
    • ActiveMQ
    • MQTT
    • NATS
  • 网关中间件

    • Nginx
  • Linux
  • Docker
  • Git
  • K8s
  • Solidity
  • Java
  • 计算机网络
  • 操作系统
GitHub (opens new window)
首页
  • JavaSE
  • JavaWeb
  • Spring生态
  • JUC
  • JVM
  • Netty
  • Java各版本特性
  • 23种设计模式
  • Maven
  • Java常用框架
  • Dubbo
  • OpenFeign
  • Nacos
  • Zookeeper
  • Sentinel
  • Seata
  • SpringCloud Gateway
  • Apollo
  • Eureka
  • Go基础
  • Gin
  • SQL数据库

    • MySQL
    • Oracle
  • NoSQL数据库

    • Redis
    • MongoDB
    • ElasticSearch
  • 消息中间件

    • RabbitMQ
    • RocketMQ
    • Kafka
    • ActiveMQ
    • MQTT
    • NATS
  • 网关中间件

    • Nginx
  • Linux
  • Docker
  • Git
  • K8s
  • Solidity
  • Java
  • 计算机网络
  • 操作系统
GitHub (opens new window)
npm

(进入注册为作者充电)

  • JAVA 项目中如何实现接口调用?
  • 什么是Feign
  • Spring Cloud Alibaba快速整合OpenFeign
    • 1)引入依赖
    • 2)编写调用接口+@FeignClient注解
    • 3)调用端在启动类上添加@EnableFeignClients注解
    • 4)发起调用,像调用本地方式一样调用远程服务
  • Spring Cloud Feign的自定义配置及使用
  • 《OpenFeign》笔记
Salmon
2025-07-23
目录

Spring Cloud Alibaba快速整合OpenFeign

# 1)引入依赖

<!‐‐ openfeign 远程调用 ‐‐>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring‐cloud‐starter‐openfeign</artifactId>
</dependency>

# 2)编写调用接口+@FeignClient注解

@FeignClient(value = "mall‐order",path = "/order")
public interface OrderFeignService {

  @RequestMapping("/findOrderByUserId/{userId}")
  public R findOrderByUserId(@PathVariable("userId") Integer userId);
}

# 3)调用端在启动类上添加@EnableFeignClients注解

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

# 4)发起调用,像调用本地方式一样调用远程服务

@RestController
@RequestMapping("/user")
public class UserController {

  @Autowired
  OrderFeignService orderFeignService;

  @RequestMapping(value = "/findOrderByUserId/{id}")
  public R findOrderByUserId(@PathVariable("id") Integer id) {
  	//feign调用
  	R result = orderFeignService.findOrderByUserId(id);
  	return result;
  }
}
上次更新: 2025/07/23, 09:25:41
什么是Feign
Spring Cloud Feign的自定义配置及使用

← 什么是Feign Spring Cloud Feign的自定义配置及使用→

Theme by Vdoing | Copyright © 2022-2025 Salmon's Blog
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式