openfeign调用异常:feign.FeignException: [405] during [GET]

feign调用异常如下:

feign.FeignException$MethodNotAllowed: [405] during [GET] to [http://order-server/order/info] [OrderClient#orderInfo(Integer)]: [{“timestamp”:”2022-05-21T13:05:49.129+00:00”,”status”:405,”error”:”Method Not Allowed”,”message”:””,”path”:”/order/info”}]
at feign.FeignException.clientErrorStatus(FeignException.java:203)
at feign.FeignException.errorStatus(FeignException.java:177)
at feign.FeignException.errorStatus(FeignException.java:169)
at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:92)

看异常信息,应该是请求方式不对, 修改请求方式为POST;
如果请求方式也正确,检查下feign请求参数,看是否缺少@RequestParam注解:

1
2
3
4
5
6
@FeignClient(value = "order-server")
public interface OrderClient {

@GetMapping("order/info")
String orderInfo(@RequestParam("orderId")Integer orderId);
}

OpenFeign需要@RequestMapping、@RequestParam、@PathVariable、@RequestHeader等来构造http请求。
此处通过添加@RequestParam(“orderId”)解决。


openfeign调用异常:feign.FeignException: [405] during [GET]
https://river106.cn/posts/dd31bb3a.html
作者
river106
发布于
2022年5月21日
许可协议