gpt4 book ai didi

java - FeignClient 将 GET 方法转换为 POST

转载 作者:行者123 更新时间:2023-12-01 01:11:01 25 4
gpt4 key购买 nike

我不知道我做错了什么,但是每次伪装客户端都将方法声明为 get to 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;
}

此设置应解决此请求: 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"
}

但是,当我这样做时它工作正常:
@RequestMapping(method = GET, value = "/clients?someValue=foo&someEnum=bar")
Client getClients();

我正在处理 spring-cloud-starter-feign 1.2.7.RELASE包含, feign-core/sl4fj/hystrix/ 9.3.1 的版本版本,但我也在 10.1.0 版本上对其进行了测试,结果相同。

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

最佳答案

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

@RequestMapping(method = GET, value = "/clients")
Client getClients(@RequestParam("someValue") String someValue, @RequestParam("someEnum") String someEnum);

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

关于java - FeignClient 将 GET 方法转换为 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53340164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com