1. エラー報告
java: 无法访问org.springframework.web.bind.annotation.RequestMapping 错误的类文件: /D:/SoftwareInstall/Maven/repository/org/springframework/spring-web/6.0.9/spring-web-6.0.9.jar!/org/springframework/web/bind/annotation/RequestMapping.class 类文件具有错误的版本 61.0, 应为 52.0 请删除该文件或确保该文件位于正确的类路径子目录中。
2. 問題の背景
バージョン情報: Spring Boot: 3.1.0、jdk: 1.8
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>first-spring-boot-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>first-spring-boot-project</name>
<description>first-spring-boot-project</description>
<properties>
<java.version>1.8</java.version>
</properties>
3. 理由の分析
SpringBoot が使用されるのは、Spring が3.0或者3.0以上
Spring6 以降のSprinBoot3.0
最小サポートを公式にリリースしているJDK17
ためです。そのため、必要なのは SpringBoot バージョンを 3.0 未満に下げる (または JDK バージョンを 17 以降にアップグレードする) だけです。
Spring Boot 3.0 には少なくとも Java 17 が必要で、上位互換性のために Java 19 をサポートしています。
4. 解決策
解決策 1: JDK バージョンをアップグレードし、JDK バージョンを JDK17 以降にアップグレードします。次のように。
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>first-spring-boot-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>first-spring-boot-project</name>
<description>first-spring-boot-project</description>
<properties>
<java.version>17</java.version>
</properties>
解決策 2: SpringBoot のバージョンを下げ、SpringBoot のバージョンを 3.0 未満に下げます。次のように。
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>first-spring-boot-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>first-spring-boot-project</name>
<description>first-spring-boot-project</description>
<properties>
<java.version>1.8</java.version>
</properties>