java 无法解析导入的org.springframework.data.jpa.repository

hjzp0vay  于 2022-12-02  发布在  Java
关注(0)|答案(1)|浏览(325)

我正在使用Spring工具套件版本4。我已经创建了一个新的Sping Boot 项目。Pom.xml如下所示:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>StudentCRUD</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>StudentCRUD</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies> 

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

我已经创建了一个实体类。这没有问题。但是当我尝试创建一个扩展接口JpaRepository的接口时,以下导入没有得到解决:
导入数据库;
我已经做了maven更新几次,并已清洁建设的项目也没有改变。这将是真的有帮助,如果有人可以指导我做了错误?

cl25kdpy

cl25kdpy1#

也许是IDE的问题?我用pom.xml导入JpaRepository没有问题。

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

public interface Repo extends JpaRepository<Long, Object> {
}

相关问题