Spring Cloud OpenFeign实战之 FeignException 405

异常描述

feign.FeignException: status 405 reading UserFeignClient#get0(User); content:

{"timestamp":1482676142940,"status":405,"error":"Method Not Allowed", "exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/user"}

FeignClient定义

@FeignClient("microservice-provider-user")

public interface UserFeignClient {

  @RequestMapping(value = "/user", method = RequestMethod.GET)

  public User get0(Long userId);

}

解决方法

明明定义的是GET请求,结果在发起service to service call时,被转换成了POST请求。原因是OpenFeign在构造请求时需要足够多的@RequestMapping/@RequestParam/@PathVariable/@RequestHeader等来构造http请求。通过阅读自己定义的FeignClient可以发现,GET请求中的参数定义缺少注解@RequestParam,故而报错。 将参数userId明确定义为@RequestParam("userId") Long userId

关注公众号交流学习

关注Java分布式架构实战, 持续精进

关注Java分布式架构实战, 持续精进

联系我,学习交流

联系我,学习交流

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值