[英]Feign Client ignoring request params
我創建了Feign Client
:
@FeignClient(name = "yandex",url="${yandex.ribbon.listOfServers}")
public interface YandexMapsRestApiServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "{geoParam}")
String getCountryInfo(@Param("geoParam") String geoParam);
}
在控制器中,我被寫道:
@Autowired
private YandexMapsRestApiServiceClient client;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String test() {
return client.getCountryInfo("Moscow");
}
我的Applicaton.yml
看起來是這樣的:
yandex:
ribbon:
listOfServers: https://geocode-maps.yandex.ru/1.x/?format=json&geocode=
ConnectTimeout: 20000
ReadTimeout: 20000
IsSecure: true
hystrix.command.default.execution:
timeout.enabled: true
isolation.thread.timeoutInMilliseconds: 50000
當我嘗試獲得一些結果時,作為回報,我得到404錯誤:
feign.FeignException: status 404 reading YandexMapsRestApiServiceClient#getCountryInfo(String); content:
在這種情況下,我在調試器中看到他feign
未設置我的geoParam
:
為什么會發生這種情況以及如何解決這個問題?
正如Musaddique所說,您正在混合Feign
和Spring
注釋。 使用Spring Cloud Feign
(OpenFeign)時,必須使用Spring注釋RequestParam
。 Feign
注釋將不被處理。
為了實現您想要的,您將需要更改配置。 url
只能是網址或服務名稱。 對URL使用查詢字符串或其他擴展名將產生意外結果。
將路徑信息移動到RequestMapping
批注,然后在其中指定查詢參數。
@FeignClient(name = "yandex", url="${yandex.ribbon.listOfServers}")
public interface YandexMapsRestApiServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/1.x?format=json&geocode={geoParam}")
String getCountryInfo(@RequestParam("geoParam") String geoParam);
}
功能區配置如下所示:
yandex:
ribbon:
listOfServers: "https://geocode-maps.yandex.ru"
ConnectTimeout: 20000
ReadTimeout: 20000
IsSecure: true
現在,使用您的client.getCountryInfo("moscow")
示例的最終URL為https://geocode-maps.yandex.ru/1.x?format=json&geocode=moscow
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.