8

I want to use Spring Data JPA with default sort direction with the latest spring-boot-starter-parent 2.2.1.RELEASE:

@Override
public Page<ProcessingLogs> findAll(int page, int size) {
    return dao.findAll(PageRequest.of(page,size, new Sort(Sort.Direction.DESC, "createdAt")));
}

But I get error:

The constructor Sort(Sort.Direction, String) is undefined

This is the latest code: https://github.com/spring-projects/spring-data-commons/blob/master/src/main/java/org/springframework/data/domain/Sort.java

Do you know how I can solve this issue?

2
  • You linked the source, did you even take a look at it? Sort.by(Sort.Direction.DESC, "createdAt");.
    – tkausl
    Commented Nov 26, 2019 at 23:03
  • 4
    ... I have to change new Sort to Sort.by Commented Nov 26, 2019 at 23:05

1 Answer 1

21

Use like this PageRequest.of(page, size, Sort.by(Sort.Direction.DESC,"createdAt"))

1
  • 3
    Just to expand. The constructor was removed and statics 'Sort.by(direction, properties)' is used in place.
    – steve
    Commented Feb 15, 2020 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.