Spring Cloud feign GET请求无法用实体传参的解决方法

代码如下:

@FeignClient(name = "eureka-client", fallbackFactory = FallBack.class, decode404 = true, path = "/client")
public interface FeignApi {
//    @PostMapping("/hello/{who}")
//    String hello(@PathVariable(value = "who") String who) throws Exception;

    @GetMapping("/hello")
    String hello(Params params) throws Exception;
}

调用报错:

feign.FeignException: status 405 reading FeignApi#hello(Params)

解决办法:

  1. 改用post请求,添加@RequestBodey注解

  2. 新增@SpringQueryMaq注解,如下:

  3. @GetMapping("/hello")
    String hello(@SpringQueryMap Params params) throws Exception;
    
posted @ 2019-06-03 23:28  明智说  阅读(456)  评论(0编辑  收藏  举报