CrudRepository cannot be resolved to a type
P.S - I know the original answer used interface not class. But as we can't ask same question again. The answer is for beginner who may missed the interface part.
We generally get this type of error when we create the repository as class instead of interface. CrudRepository is an interface, you most probably extend it using an interface only:
Wrong (Some times when we create the repository we create a class by mistake ):
public class MovieRepository extends CrudRepository<Movie, Long>
Error: CrudRepository cannot be resolved to a type
Just changed it to interface:
public interface MovieRepository extends CrudRepository<Movie, Long>
It looks like it was an issue with Maven libraries. I deleted the whole content in .m2/repository
and ran Maven > Update project
in Eclipse, so that Maven had to download the whole content again. No more error after this!
Edit
As pointed out by user3578953, executing maven-clean does the same thing that I did by deleting the whole m2 repository content. I didn't know much about Maven when I first asked this question, but this is obviously a better way to solve the issue.
If you are having this problem, check if the org.springframework.data.repository.CrudRepository import is working. If it is then this answer probably won't be the solution. If it is not working and the "data" part is highlighted, then check your pom.xml and if you don't have it already, add the following dependency to it:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
After adding the dependency, delete your local .m2 directory and build from the command-line. You may also want to reimport the maven project to your workspace.