feign java
- IT科技
- 關注:1.21W次
<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://shqsg.com/dianzi/k3lw26.html