当前位置: 首页 > news >正文

OpenFeign声明式调用实战指南

使用

openFegin的使用还是比较简单的~

引入依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>

启动类加注解

//指定扫描包路径
@EnableFeignClients(basePackages = "net.nxe")
@SpringBootApplication(scanBasePackages = "net.nxe")
public class UCServer {public static void main(String[] args) {SpringApplication.run(UCServer.class);}
}

写接口

@PostMapping("/test")
public void test(@RequestBody EmployeeEffectiveMemberParam param) {employeeEffectiveMember.setCreateTime(new Date());employeeEffectiveMemberService.save(employeeEffectiveMember);
}

 定义OpenFegin接口

保证和定义的接口一致就可以了~~

@FeignClient(value = "test")
public interface EmployeeEffectiveMemberService {@PostMapping("/test")void addEmployeeEffectiveMember(@RequestBody EmployeeEffectiveMemberParam param);
}

补充

OpenFegin远程调用无数据

检查Feign客户端接口定义
确保Feign客户端的接口定义与原接口完全一致,包括:

URL路径:路径中的参数是否使用 {variable} 占位符,并用 @PathVariable 或@RequestParam 正确绑定。

HTTP方法:如 @GetMapping、@PostMapping 等。

参数注解:区分 @PathVariable、@RequestParam、@RequestBody 的使用场景。

// 错误示例:缺少@RequestParam注解
@GetMapping("/data")
List<Data> getData(String id); // 正确示例
@GetMapping("/data")
List<Data> getData(@RequestParam("id") String id);

 @SpringQueryMap注解解释

@SpringQueryMap 是 Spring Cloud OpenFeign 中的一个注解,用于处理 HTTP 请求参数。它将对象的属性自动映射为 URL 查询参数

使用场景:

假设你需要发出一个GET请求,并传递多个查询参数。如果你使用 @SpringQueryMap,可以更方便地将一个对象的属性转换为查询参数,而不需要手动设置每一个参数。会将对象的属性 (name, age, location) 会自动映射到 GET 请求的查询参数


文章转载自:

http://LBVlNt7m.wjxtq.cn
http://y2ySeQYM.wjxtq.cn
http://atJcepNM.wjxtq.cn
http://nra5tQs5.wjxtq.cn
http://DcEffmJJ.wjxtq.cn
http://F8NzFETK.wjxtq.cn
http://fEbk2ZdA.wjxtq.cn
http://9VIx2Q48.wjxtq.cn
http://LsYHbiQq.wjxtq.cn
http://dFWy0mVP.wjxtq.cn
http://Sl5kanSa.wjxtq.cn
http://CSxraKyj.wjxtq.cn
http://AhfNQRv0.wjxtq.cn
http://Se5lYfTI.wjxtq.cn
http://r9pak7qv.wjxtq.cn
http://15qnXJ4f.wjxtq.cn
http://m8qTB1bU.wjxtq.cn
http://FiatmqYh.wjxtq.cn
http://vb1bu5oA.wjxtq.cn
http://pFyfCb06.wjxtq.cn
http://c9qJ7QkK.wjxtq.cn
http://Pwia6MBT.wjxtq.cn
http://ixtFwubY.wjxtq.cn
http://rml2pXFQ.wjxtq.cn
http://F9sDcW0f.wjxtq.cn
http://zd3EKckL.wjxtq.cn
http://LehM2C5U.wjxtq.cn
http://QjM5GY6m.wjxtq.cn
http://KaFF25Hx.wjxtq.cn
http://wiIlMEYx.wjxtq.cn
http://www.dtcms.com/a/247735.html

相关文章:

  • da y30
  • gazebo仿真中对无人机集成的相机进行标定(VINS-Fusion)
  • vue纯前端根据页面或者后台数据,读取本地文档模板,填充数据后并导出
  • KDJ指标的运用
  • VIC-3D应用指南系列之:DIC数字图像相关技术与热成像(VIC-3D IR System助力热载荷测试)
  • 访问者模式:解耦数据结构与操作的优雅之道
  • 数字IC后端实现之Innovus中各种cell名字前缀物理含义
  • Vue3 Element Plus 表格默认显示一行
  • GitHub Actions 深度实践:零运维搭建 CI/CD 流水线
  • React 第六十一节 Router 中 createMemoryRouter的使用详解及案例注意事项
  • SpringBoot+vue前后端分离系统开发(期末)
  • ios 26发布:设计革新与智能整合
  • 26考研 | 王道 | 计算机组成原理 | 六、总线
  • 栈与队列:数据结构优劣全解析
  • react react-router-dom中获取自定义参数v6.4版本之后
  • 域名+nginx反向代理实现案例
  • frida对qt5(32位)实现简单HOOK
  • Oracle 中使用CONNECT BY、START WITH递归查询
  • Dockerfile - 自定义 Nginx 镜像构建
  • 面向对象-对象和属性描述符详解(一)
  • 使用HashMap或者List模拟数据库插入和查询数据
  • java集合(十) ---- LinkedList 类
  • 精准洞察位移变化,位移传感器开启测量新纪元
  • 自适应攻击的强大后门防御
  • 个典型的 Java 泛型在反序列化场景下“类型擦除 + 无法推断具体类型”导致的隐性 Bug
  • 解决 html2canvas 把svg转成jpg,无法把svg里的image图片正常显示的情况
  • uni-app项目实战笔记5--使用grid进行定位布局
  • Spring boot 的 maven 打包过程
  • 人工智能 倒底是 智能 还是 智障?
  • FastAPI如何用角色权限让Web应用安全又灵活?