網站首頁 美容小常識 享受生活 東方時尚 識真假 高奢 資訊 遊戲攻略 搞笑段子
當前位置:品位站 > 享受生活 > 心理

openfeign使用教程

欄目: 心理 / 發佈於: / 人氣:3.29W
openfeign使用教程

1 OpenFeign使用步驟

引入OpenFeign依賴

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> 12341234

啟動類上增加註解@EnableFeignClients

編寫聲明式調用Client

//註解裏面的值是:被調用服務的服務名 @FeignClient("gulimall.coupon") public interface CouponClient { //與被調用服務的controller一致即可,記得Mapping是填完整路徑 @GetMapping("/test") String test() } 1234567812345678

直接注入client調用方法即可,此處以測試的controller為例

@RestController @RequestMapping("/") public class TestController { @Resource private CouponClient client @GetMapping("/test") public String test(){ return client.test() } } 123456789101112123456789101112

Tags:openfeign