今天搭建了一个简单的 Spring Boot 应用,结果启动报错了,错误信息如下:
/Users/shifeifei/Projects/note-example/example-dubbo/example-dubbo-01/dubbo-01-provider/src/main/java/com/example/dubbo01/provider/Dubbo01ProviderApplication.java:3:32
java: 无法访问org.springframework.boot.SpringApplication
错误的类文件: /Users/shifeifei/.m2/repository/org/springframework/boot/spring-boot/3.1.0/spring-boot-3.1.0.jar!/org/springframework/boot/SpringApplication.class
类文件具有错误的版本 61.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。
导致启动失败的原因:
- 因为平时工作开发使用
Spring Boot的版本是2.7.*,JDK版本是1.8,而我搭建的这个项目使用了Spring Boot的3.1.0版本 - 解决该问题的方式是降低
Spring Boot的版本到2.7.*;或者使用JDK 17
一、如何查看Spring Boot 各种版本
当然也可以查看
Tags,查看版本号
二、如何查看Spring Boot需要的环境信息
1. 如何查找相关文档
(1)进入Spring官网,spring.io/
(2)选择 Projects -> Spring Boot
(3)选择 LEARN -> Reference Doc
(4)选择 Getting Started -> System Requirements
2. 常用Spring Boot版本
2.7.12版本
docs.spring.io/spring-boot…
3.0.7版本
docs.spring.io/spring-boot…
3.1.0版本
docs.spring.io/spring-boot…
三、错误信息中的 61 、52又是啥东西
它是Java的class文件结构中的一个字段,叫major_version;
具体参考Oracle官方文档:
docs.oracle.com/javase/spec…
| Java SE | Released | Major | Supported majors |
|---|---|---|---|
| 1.0.2 | May 1996 | 45 | 45 |
| 1.1 | February 1997 | 45 | 45 |
| 1.2 | December 1998 | 46 | 45 .. 46 |
| 1.3 | May 2000 | 47 | 45 .. 47 |
| 1.4 | February 2002 | 48 | 45 .. 48 |
| 5.0 | September 2004 | 49 | 45 .. 49 |
| 6 | December 2006 | 50 | 45 .. 50 |
| 7 | July 2011 | 51 | 45 .. 51 |
| 8 | March 2014 | 52 | 45 .. 52 |
| 9 | September 2017 | 53 | 45 .. 53 |
| 10 | March 2018 | 54 | 45 .. 54 |
| 11 | September 2018 | 55 | 45 .. 55 |
| 12 | March 2019 | 56 | 45 .. 56 |
| 13 | September 2019 | 57 | 45 .. 57 |
| 14 | March 2020 | 58 | 45 .. 58 |
| 15 | September 2020 | 59 | 45 .. 59 |
| 16 | March 2021 | 60 | 45 .. 60 |
| 17 | September 2021 | 61 | 45 .. 61 |
| 18 | March 2022 | 62 | 45 .. 62 |
| 19 | September 2022 | 63 | 45 .. 63 |
| 20 | March 2023 | 64 | 45 .. 64 |