java feign
- IT科技
- 关注:1.43W次
<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
很多朋友都想知道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)
- 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/itkeji/ve054z.html