FeignClient 将 GET 方法转换为 POST

Kam*_*l W 6 java spring spring-cloud-feign feign

我不知道我做错了什么,但每次 feign 客户端都会将声明为 get 的方法转换为 post 类型。

@FeignClient(name = "my-service", url = "http://localhost:8114", path = "service")
public interface MyServiceClient {

    @RequestMapping(method = GET, value = "/clients")
    Client getClients(@QueryMap MyPojo pojo);
}

@Getter
@Setter
public class MyPojo {

    @NotNull
    private String someValue;
    @NotNull
    private SomeEnum someEnum;
}
Run Code Online (Sandbox Code Playgroud)

此设置应解决此请求:
GET http://localhost:8114/service/clients?someValue=foo&someEnum=bar

但每次我得到这个结果:

{
  "timestamp": 1542378765498,
  "status": 405,
  "error": "Method Not Allowed",
  "exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
  "message": "Request method 'POST' not supported",
  "path": "/service/clients"
}
Run Code Online (Sandbox Code Playgroud)

然而,当我这样做时,效果很好:

@RequestMapping(method = GET, value = "/clients?someValue=foo&someEnum=bar")
Client getClients();
Run Code Online (Sandbox Code Playgroud)

我正在开发spring-cloud-starter-feign 1.2.7.RELASE包含feign-core/sl4fj/hystrix/ 9.3.1version 的版本,但我也在 10.1.0 版本上测试了它,结果相同。

我应该怎么做才能解决这个问题?

Kam*_*l W 4

在我的项目中,我使用spring-cloud-dependencies包含Camden.SR7feign 版本的版本9.3.1,目前最新版本是Finchley.RELEASE包含 feign的版本9.7,我看到它专用于spring-boot 2.x.x,但我的整个基础设施(config/eureka 服务器)运行,1.5.x因此它会产生下一个问题。我查看了 feign 的 github 文档,发现@Param注释可能会有所帮助,但是当我在带有 3 个参数的方法中使用它时,它会抛出异常Method has too many Body parameters~。最后,来自 spring 的注释@RequestParam可以作为解决方法,但我没有找到任何可以组合这些注释的信息来源。

@RequestMapping(method = GET, value = "/clients")
Client getClients(@RequestParam("someValue") String someValue, @RequestParam("someEnum") String someEnum);
Run Code Online (Sandbox Code Playgroud)

我没有找到spring-cloud-dependencies包含9.7feign 且专用于spring-boot 1.5.x应用程序的版本。