很多朋友都想知道java feign是什么?下面就一起來(lái)了解一下吧~
Feign?是一種聲明式、模板化的?HTTP客戶(hù)端,在Spring Cloud中使用?Feign, 在HTTP請(qǐng)求遠(yuǎn)程服務(wù)時(shí)能與調(diào)用本地方法一樣的編碼體驗(yàn),開(kāi)發(fā)者完全感知不到這是遠(yuǎn)程方法,更感知不到這是個(gè)HTTP請(qǐng)求。比如:
@Autowired private?AdvertGropRemoteService?service;?//?遠(yuǎn)程服務(wù) public?AdvertGroupVO?foo(Integer?groupId)?{? return?service.findByGroupId(groupId);?//?通過(guò)HTTP調(diào)用遠(yuǎn)程服務(wù)? }
開(kāi)發(fā)者通過(guò)service.findByGroupId()就能完成?發(fā)送HTTP請(qǐng)求?和?解碼HTTP返回結(jié)果?并?封裝成對(duì)象?的過(guò)程。 @FeignClient(name?=?"ea")??//?用于通知Feign組件對(duì)該接口進(jìn)行代理(不需要編寫(xiě)接口實(shí)現(xiàn)),使用者可直接通過(guò)@Autowired注入 public?interface?AdvertGroupRemoteService?{ @RequestMapping(value?=?"/group/{groupId}",?method?=?RequestMethod.GET)??//?表示在調(diào)用該方法時(shí)需要向/group/{groupId}發(fā)送GET請(qǐng)求。 AdvertGroupVO?findByGroupId(@PathVariable("groupId")?Integer?adGroupId)?//?與SpringMVC中對(duì)應(yīng)注解含義相同 @RequestMapping(value?=?"/group/{groupId}",?method?=?RequestMethod.PUT) void?update(@PathVariable("groupId")?Integer?groupId,?@RequestParam("groupName")?String?groupName)
以上就是小編今天的分享,希望可以幫到大家。