zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    python基础 条件和循环
    git基本使用(搭建Git服务器)
    面试题整理
    node nvm npm nrm 安装
    onmouse事件
    webpack
    web前端UI框架
    javascript cookie
    三大家族,offset,scroll,client
    clientTop,scrollTop,兼容
  • 原文地址:https://www.cnblogs.com/yuzhaoblog/p/8416274.html
Copyright © 2011-2022 走看看