PagingAndSortingRepository cannot be resolved

Viewed 20145

I'm try to use PagingAndSortingRepository from Spring Data:

import org.springframework.data.jpa.repository.JpaRepository;

public interface StudentRepository extends JpaRepository<Student, Integer> {}

But I receive this error:

org.springframework.data.repository.PagingAndSortingRepository can't be resolved

What wrong with my code and how can I fix it?

5 Answers

This one solved issue for me

Gradle

// https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.1.RELEASE'

Maven

<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>

I resolved this including spring-data-commons that included PagingAndSortingRepository

<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons -->
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>

enter image description here

Make sure the jar is installed.

 mvn clean dependency:tree

2) This what did it for me: enter image description here

Delete ~.m2/org/springframework.data folder and Update maven project.

If you have <artifactId>spring-data-commons</artifactId> dependency and <artifactId>spring-data-jpa</artifactId> both, then this issue will occur.

Remove the <artifactId>spring-data-commons</artifactId> dependency.

Related