我正在开发一个 Spring MVC 项目,我想创建一个扩展 JpaRepository 的存储库接口。但是,我遇到编译错误,表明某些 JAR 文件可能丢失或 JAR 之间存在冲突。
这是我的存储库界面:
public interface StudentRepository extends JpaRepository<Student , Long> {
}
我已在我的项目中包含以下 JAR 文件:
尽管添加了这些 JAR 文件,问题仍然存在。我错过了什么或做错了什么?如何解决这些编译错误?
根据您提供的信息,我唯一能提供的帮助如下:
可以直接跳到下一段
Jar List
看看有没有以下文件?
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>helloworldwebapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>helloworld Maven Webapp</name>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>6.1.10</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
<build>
<finalName>helloworld</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvn dependency:copy-dependencies -DoutputDirectory=target/libs
target/libs
├── antlr4-runtime-4.13.0.jar
├── jakarta.annotation-api-2.0.0.jar
├── jakarta.persistence-api-3.2.0.jar
├── micrometer-commons-1.12.7.jar
├── micrometer-observation-1.12.7.jar
├── slf4j-api-2.0.2.jar
├── spring-aop-6.1.9.jar
├── spring-beans-6.1.9.jar
├── spring-context-6.1.9.jar
├── spring-core-6.1.9.jar
├── spring-data-commons-3.3.1.jar
├── spring-data-jpa-3.3.1.jar
├── spring-expression-6.1.9.jar
├── spring-jcl-6.1.9.jar
├── spring-jdbc-6.1.10.jar
├── spring-orm-6.1.10.jar
└── spring-tx-6.1.9.jar
现在请检查以下列表中的 jar 文件。你下载了吗
mvn dependency:tree
+- org.springframework.data:spring-data-jpa:jar:3.3.1:compile
| +- org.springframework.data:spring-data-commons:jar:3.3.1:compile
| +- org.springframework:spring-context:jar:6.1.9:compile
| | +- org.springframework:spring-expression:jar:6.1.9:compile
| | \- io.micrometer:micrometer-observation:jar:1.12.7:compile
| | \- io.micrometer:micrometer-commons:jar:1.12.7:compile
| +- org.springframework:spring-aop:jar:6.1.9:compile
| +- org.springframework:spring-tx:jar:6.1.9:compile
| +- org.springframework:spring-beans:jar:6.1.9:compile
| +- org.springframework:spring-core:jar:6.1.9:compile
| | \- org.springframework:spring-jcl:jar:6.1.9:compile
| +- org.antlr:antlr4-runtime:jar:4.13.0:compile
| +- jakarta.annotation:jakarta.annotation-api:jar:2.0.0:compile
| \- org.slf4j:slf4j-api:jar:2.0.2:compile
+- org.springframework:spring-orm:jar:6.1.10:compile
| \- org.springframework:spring-jdbc:jar:6.1.10:compile
\- jakarta.persistence:jakarta.persistence-api:jar:3.2.0:compile