码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA Feign

时间:2018-02-05 10:33:33      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:ber   title   pos   red   调用   mvc   autowire   interface   string   

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)

 

JAVA Feign

标签:ber   title   pos   red   调用   mvc   autowire   interface   string   

原文地址:https://www.cnblogs.com/yuzhaoblog/p/8416274.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!