我正在关注this tutorial使用Spring创建一个CRUD应用程序。我想创建一个存储库,我希望它扩展Spring CrudRepository:
package com.movieseat.repositories;
import java.io.Serializable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.movieseat.models.Movie;
public interface MovieRepository extends CrudRepository<Movie, Serializable> {}
Visual Studio Code说:
无法解析导入org.springframework.data
我已删除.m2文件夹中的存储库文件夹并重新安装但仍未成功。
我想我的pom.xml文件中缺少一个依赖项,但我找不到它。
//编辑。共享后端文件夹中的pom.xml:
<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>
<artifactId>backend</artifactId>
<name>backend</name>
<description>The backend project</description>
<parent>
<groupId>com.jdriven.ng2boot</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.movieseat.Application</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jdriven.ng2boot</groupId>
<artifactId>frontend</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:3)
教程中的gradle文件导入以下Spring data JPA
依赖项
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
...
}
它的maven等价物是:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.7.RELEASE</version>
</dependency>
因此,您必须在pom文件中添加上述依赖项。
答案 1 :(得分:1)
使用以下Maven依赖
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
您可以根据您使用的Spring版本更改它的版本。 用户关注链接。 https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core