Feign使用注意事项

springcloud 寻梦 4年前 (2021-01-25) 537次浏览 0个评论 扫描二维码
文章目录[隐藏]

一、FeignClient接口,不能使用@GettingMapping 之类的组合注解

@RequestMapping(value = "/dream/{id}", method = RequestMethod.GET)不能写成@GetMapping("/dream/{id}")

二、FeignClient接口中,如果使用到@PathVariable ,必须指定其value

@RequestMapping(value = "/simple/{id}", method = RequestMethod.GET)

三、FeignClient多参数的构造

如果想要请求microservice-provider-user 服务,并且参数有多个例如:http://microservice-provider-user/query-by?id=1&username=张三

@FeignClient("microservice-provider-user")public interface UserFeignClient {@RequestMapping(value = "/query-by", method = RequestMethod.GET)public User queryBy(User user);...}

直接使用复杂对象:

该请求不会成功,只要参数是复杂对象,即使指定了是GET方法,feign依然会以POST方法进行发送请求

喜欢 (2)
[支付宝扫码,感谢支持]
分享 (0)
关于作者:

您必须 登录 才能发表评论!