我正在按照本教程使用 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> {}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
您教程中的 gradle 文件导入了以下Spring data JPA依赖项
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
...
}
Run Code Online (Sandbox Code Playgroud)
它的 maven 等价物是:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.7.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
因此,您必须在 pom 文件中添加上述依赖项。
| 归档时间: |
|
| 查看次数: |
7893 次 |
| 最近记录: |