Smajl Smajl - 1 year ago 164
Java Question

Spring Boot JPA - paging and sorting

I am trying to implement pagination to my Spring Data JPA repository in Spring Boot but I am stuck with the following exception when running uni tests:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate []: Specified class is an interface
at org.springframework.web.servlet.FrameworkServlet.processRequest(

Could someone point out to me what am I missing here? This is my repository:

public interface VenueRepository extends PagingAndSortingRepository<Venue, Long> {

public Page<Venue> findAll(Pageable pageable);


and controller:

public class VenueController {

private VenueRepository venueRepo;

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Page<Venue>> getVenues(Pageable pageable) {
return new ResponseEntity<>(venueRepo.findAll(pageable), HttpStatus.OK);

and finally my test:

public void responseOkVenuesTest() throws Exception {

I spent couple of hours trying to make this work and am running out of ideas. Thank you for any tips!

Answer Source

Change your method getVenues in the way that you can pass the parameters to instantiate a PageRequest instead of passing Pageable :

 @RequestMapping(method = RequestMethod.GET)
  public ResponseEntity<List<Venue>> getVenues(int from,int to) {
     return new ResponseEntity<>(
        venueRepo.findAll((new PageRequest(from, to)), HttpStatus.OK).getContent();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download