我正在使用Maven在Spring Boot項目(由Spring Initializr生成)上工作。我想創建一個CrudRepository,但是我收到錯誤「CrudRepository無法解析爲某個類型」,而包org.springframework.data.repository不包含CrudRepository類。我試圖按照一堆教程來了解什麼是錯誤的,但我沒有找到任何東西。我的POM對我來說很合適,當我運行maven clean和package目標時,我沒有任何構建失敗,我嘗試更新項目並下載源代碼,但沒有任何效果。 Eclipse無法找到CrudRepository類。CrudRepository無法解析爲類型
這裏是我的POM文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myquickstart</groupId>
<artifactId>SpringQuickstart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringQuickstart</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
而且我的倉庫:
package com.myquickstart.repositories;
import org.springframework.stereotype.Repository;
import org.springframework.data.repository.CrudRepository;
import com.myquickstart.entities.Movie;
@Repository
public interface MovieRepository extends CrudRepository<Movie, Long> {
}
感謝您的幫助
編輯:
我已經更新項目在Eclipse中使用「Maven => Update項目」。在那之後,我在「問題」的觀點得到這個錯誤:
C:/Users/carrm/.m2/repository/org/hibernate/hibernate-core/5.0.11.Final/hibernate-core-5.0.11.Final.jar' in project 'SpringQuickstart' cannot be read or is not a valid ZIP file
我不知道知道如何解決這個問題/什麼是我的CrudRepository問題的鏈接。在命令行($ mvn spring-boot:run
)
- 建設項目與Maven:
right click on project-Maven-update project
您是如何更新項目的? –
我在Eclipse中使用了「Maven => Update project」 – Carrm