Spring Data Pageable not supported as RequestParam in Feign Client

情到浓时终转凉″ 提交于 2019-12-04 20:04:31

I think your code doesn't work because you are using @RequestParam annotation for Pageable parameter in your Feign method.

My implementation of such a method works as expected.

Client:

@FeignClient(name = "model-service", url = "http://localhost:8080/")
public interface ModelClient {
    @GetMapping("/models")
    Page<Model> getAll(@RequestParam(value = "text", required = false) String text, Pageable page);
}

Controller:

@GetMapping("/models")
Page<Model> getAll(@RequestParam(value = "text", required = false, defaultValue = "text") String text, Pageable pageable) {
    return modelRepo.getAllByTextStartingWith(text, pageable);
}

Note that in my case, without exposing PageJacksonModule as a bean, Spring raised the exception:

InvalidDefinitionException: Cannot construct instance of org.springframework.data.domain.Page

So I had to add it to the project:

@Bean
public Module pageJacksonModule() {
    return new PageJacksonModule();
}

My working demo: github.com/Cepr0/sb-feign-client-with-pageable-demo

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