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