首页 > 生活美容 > 心理 > openfeign使用教程

openfeign使用教程

   来源:秀美库    阅读: 3.41W 次
字号:

用手机扫描二维码 在手机上继续观看

手机查看
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

减肥
家居
健康
情感
婚姻
亲子
星座
宠物