java: 无法访问org.springframework.web.bind.annotation.RequestMapping......类文件具有错误的版本 61.0, 应为 52.0

文章目录

  • 一、报错问题
  • 二、问题背景
  • 三、原因分析
  • 四、解决方案

一、报错问题

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>
  • 21
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值