1

I have got "org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface" every time I call rest controller method with Pageable parameter. Others controller methods work fine.

  1. I have made the configuration class called PaginationConfig in which I implement @EnableSpringDataWebSupport annotation.
  2. I override addArgumentResolvers in PaginationConfig class.
  3. I updated swagger springfox from 2.7.0 to 2.9.2 version.
@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
public class PaginationConfig extends SpringDataWebConfiguration {

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver(sortResolver());
        resolver.setFallbackPageable(new PageRequest(0, 50));
        resolver.setSizeParameterName("p");
        resolver.setPageParameterName("s");
        argumentResolvers.add(resolver);
        super.addArgumentResolvers(argumentResolvers);
    }
}
@RestController
@RequestMapping("/element")
public class ElementController {

    ...

    @GetMapping("/pageable")
    public Page<Element> getAll(Pageable pageable) {
        return finder.getAll(pageable);
    }
}

When I call this

http://localhost:8000/element/pageable?p=0&s=20

I wanna get normal Page object with proper content.

pierug
  • 11
  • 2
  • I have got 4.3.24.RELEASE of org.springframework version – pierug Jun 10 '19 at 20:55
  • Also when I set brakepoint on addArgumentResolvers method, debugger reaches this code and new argument resolver is set. – pierug Jun 10 '19 at 21:13
  • The type `Pageable` [is not supported as a method argument](https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-arguments) for a controller method. See the link for the list of supported types. If the type of a method argument is not one of the supported types, it can either be a simple type (`String`, `Integer`, etc.) or a model attribute (see the last row in the table at the linked document). In this case, the controller could accept `page` and `pageSize` as method arguments and create a `Pageable` from them as `PageRequest.of(page, pageSize)`. – manish Jun 11 '19 at 04:13
  • But as you can see in [@EnableSpringDataWebSupport](https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/web/config/EnableSpringDataWebSupport.html) automatically register PageableHandlerMethodArgumentResolver which to allow injection of Pageable instances into controller methods automatically created from request parameters. Here is [tutorial with this example](https://reflectoring.io/spring-boot-paging/). – pierug Jun 11 '19 at 06:40

0 Answers0