• JAVA Feign


    Feign 是一种声明式、模板化的 HTTP客户端 

    在Spring Cloud中使用 Feign, 我们可以做到使用HTTP请求远程服务时能与调用本地方法一样的编码体验,开发者完全感知不到这是远程方法,更感知不到这是个HTTP请求。比如:

      @Autowired
      private AdvertGropRemoteService service; // 远程服务
    
      public AdvertGroupVO foo(Integer groupId) {
          return service.findByGroupId(groupId); // 通过HTTP调用远程服务
      }

    开发者通过service.findByGroupId()就能完成 发送HTTP请求 解码HTTP返回结果封装成对象 的过程。

      @FeignClient(name = "ea")  // 用于通知Feign组件对该接口进行代理(不需要编写接口实现),使用者可直接通过@Autowired注入

      public interface AdvertGroupRemoteService {

        @RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET)  // 表示在调用该方法时需要向/group/{groupId}发送GET请求。

        AdvertGroupVO findByGroupId(@PathVariable("groupId") Integer adGroupId) // 与SpringMVC中对应注解含义相同

        @RequestMapping(value = "/group/{groupId}", method = RequestMethod.PUT)

        void update(@PathVariable("groupId") Integer groupId, @RequestParam("groupName") String groupName)

  • 相关阅读:
    优酷视频下载,优酷真实地址解析
    vim配置入门,到豪华版vim配置
    python字典实现三级菜单
    python 购物车
    来到博客园的第一天
    python urllib模块使用详解
    ubutun升级命令
    SQL注入笔记
    Ajax_showHint() 函数
    轮播图中遇到的问题
  • 原文地址:https://www.cnblogs.com/yuzhaoblog/p/8416274.html
Copyright © 2020-2023  润新知