SpringBoot项目编译报错 类文件具有错误的版本 61.0, 应为 52.0

springboot项目在编译时报错:

bash 复制代码
/Users/Apple/Developer/art/caicai/cai-api/dubbo-samples/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/src/main/java/org/apache/dubbo/springboot/demo/provider/ProviderApplication.java:22:32
java: 无法访问org.springframework.boot.SpringApplication
  错误的类文件: /Users/Apple/.m2/repository/org/springframework/boot/spring-boot/3.2.3/spring-boot-3.2.3.jar!/org/springframework/boot/SpringApplication.class
    类文件具有错误的版本 61.0, 应为 52.0
    请删除该文件或确保该文件位于正确的类路径子目录中。

经过百度了发现是springboot版本过高,项目的pom文件中我的springboot版本为3.0,而java的版本为1.8,导致不匹配报错。

原先的pom文件:

java 复制代码
<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <dubbo.version>3.3.1</dubbo.version>
    <spring-boot.version>3.2.3</spring-boot.version>
</properties>

解决办法:降低springboot的版本。

修改后的pom文件:

bash 复制代码
<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <dubbo.version>3.3.1</dubbo.version>
    <spring-boot.version>2.6.13</spring-boot.version>
</properties>

编译结果:

bash 复制代码
[INFO] Dubbo Samples Spring Boot .......................... SUCCESS [  0.218 s]
[INFO] dubbo-samples-spring-boot-interface ................ SUCCESS [  0.006 s]
[INFO] dubbo-samples-spring-boot-provider ................. SUCCESS [  1.816 s]
[INFO] dubbo-samples-spring-boot-consumer ................. SUCCESS [  0.046 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.243 s
[INFO] Finished at: 2024-11-09T14:19:18+08:00
[INFO] ------------------------------------------------------------------------
进程已结束,退出代码为 0

参考链接:https://blog.csdn.net/simonchi/article/details/126625381

相关推荐
copyer_xyf几秒前
Agent 流程编排
后端·python·agent
copyer_xyf26 分钟前
Agent RAG
后端·python·agent
copyer_xyf29 分钟前
【RAG】向量数据库:milvus
后端·python·agent
铁皮饭盒30 分钟前
Bun 哪比 Node.js 快?
javascript·后端
copyer_xyf44 分钟前
Agent 记忆管理
后端·python·agent
葫芦和十三7 小时前
图解 MongoDB 02|BSON:你以为存的是 JSON,其实是带类型的二进制
后端·mongodb·agent
葫芦和十三7 小时前
图解 MongoDB 01|文档数据库
后端·mongodb·agent
陈随易10 小时前
VSCode的Copilot扩展支持接入DeepSeek,Kimi了!
前端·后端·程序员
我不是外星人11 小时前
有了 Harness Engineering ,真的还需要研发工程师吗?
前端·后端·ai编程
candyTong11 小时前
RTK 技术原理:一次典型会话里,80% 上下文是怎么省下来的
javascript·后端·架构