feign 是一个让rest服务调用更简洁的开源项目,很多介绍文章或书也称它为声明式REST调用。传统的web service中,通过引用wsdl来自动生成一些client的代理类(或stub代码),feign跟这个有点类似,但是更灵活。

先回顾一下,上节中service-consumer对服务的调用代码:

1    @GetMapping("/order/{userId}/{orderNo}")
2     public String findOrder(@PathVariable Integer userId, @PathVariable String orderNo) {
3         UserDTO user = restTemplate.getForEntity("http://SERVICE-PROVIDER-DEMO/user/" + userId, UserDTO.class).getBody();
4         if (user != null) {
5             return user.getUserName() + " 的订单" + orderNo + " 找到啦!";
6         }
7  
8         return "用户不存在!";
9     }
View Code

相关文章:

  • 2021-07-19
  • 2021-11-16
  • 2021-08-12
  • 2022-12-23
  • 2021-11-24
  • 2022-03-03
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2021-04-21
  • 2021-12-04
  • 2022-12-23
  • 2021-08-05
  • 2022-01-26
  • 2021-10-04
相关资源
相似解决方案