how to pass Spring Pageable to FeignClient

旧巷老猫 提交于 2020-08-10 03:38:33

问题


as I wrote in this issue: https://github.com/spring-cloud/spring-cloud-openfeign/issues/375 and in this SO question: Spring data Pageable does not work with feign client

I have some problems sending a Pageable object in a POST request containing a @requestbody element.

First I tried sending the Pageable embedded in my RequestBody since it was generated as example when using springdoc-openapi-webmvc-core.

Example:

@PostMapping("/search") public Page<HelloDto> searchHellos(@RequestBody HelloDto example, Pageable pageable)

{ "example": { "message": "string" }, "pageable": { "pageNumber": 0, "pageSize": 50, "offset": 10, "sort": { "sorted": false, }, "paged": true, } }

No I learned, that I can send it via Query parameter aswell and it will be parsed. The annotation that extracts the pageable into QueryParams is called org.springdoc.api.annotations.ParameterObject in SpringDoc.

@PostMapping("/search") public Page<HelloDto> searchHellos(@RequestBody HelloDto example, @ParameterObject Pageable pageable) { return helloCallerService.callHelloServiceClient(example, pageable); }

When I try to call a similar controller interface via feign like this client interface:

@PostMapping("/search") public Page<HelloDto> searchHellos(@RequestHeader("apiKey") String apiKey, @RequestBody HelloDto example, Pageable pageable);

The application won't start since the method "has too many body params". I tried to annotate Pageable with @RequestParam but it won't be recognized / parsed.

My question is:

Can we use a custom AnnotatedParameterProcessor for e.g. @ParameterObject that flats out the ParameterObject and encodes it into the url query parameters?

How would you do that? Or is the AnnotatedParameterProcessor the wrong way? Do I maybe need an expander or anything?


回答1:


Your question is more related to feign usage than springdoc-openapi. Using using org.springframework.cloud.openfeign.SpringQueryMap, solves your problem.



来源:https://stackoverflow.com/questions/63152147/how-to-pass-spring-pageable-to-feignclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!