文章目錄
- 一、報錯問題
- 二、問題背景
- 三、原因分析
- 四、解決方案
一、報錯問題
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 請刪除該文件或確保該文件位于正確的類路徑子目錄中。
二、問題背景
版本信息: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>
三、原因分析
SpringBoot使用了3.0或者3.0以上
,因為Spring官方發布從Spring6以及SprinBoot3.0
開始最低支持JDK17
,所以僅需將SpringBoot版本降低為3.0以下即可(或者將JDK版本升級為17及以上)。
Spring Boot 3.0 最低要求 Java 17,并向上兼容支持 Java 19。
四、解決方案
方案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>