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