在使用springboot创建简单web项目时,基于环境如jdk版本,springboot版本会遇到如下两个问题:
一.无效的源发行版:18 解决

解决方案:
1.进入Project Structure中检查SDKs是否是1.8版本

2. Project Structure中检查检查Modules

3.查看project

4.到setting下检查模块是否是1.8版本

5.最后检查pom文件是否是1.8版本

二.报错内容及截图如下
java: 无法访问org.springframework.web.bind.annotation.RequestMapping
错误的类文件: /D:/maven_repo/org/springframework/spring-web/6.1.5/spring-web-6.1.5.jar!/org/springframework/web/bind/annotation/RequestMapping.class
类文件具有错误的版本 61.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。

项目框架使用版本:springboot版本为3.2.4,jdk版本1.8

SpringBoot使用了3.0或者3.0以上,因为Spring官方发布从Spring6以及SprinBoot3.0开始最低支持JDK17,所以仅需将SpringBoot版本降低为3.0以下即可(或者将JDK版本升级为17及以上)。
解决方案:
方案1:升级JDK版本,将JDK版本升级为JDK17及以上版本。如下所示。
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.4</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>
————————————————
本文讲述了在使用SpringBoot3.2.4创建Web项目时,因JDK版本不匹配导致的问题,包括无效源发行版和RequestMapping类版本错误。提供了升级JDK至17或降低SpringBoot版本至3.0以下的解决方案。
3287

被折叠的 条评论
为什么被折叠?



