Recurrence directory
1. Reproduce the error
I started the project today, but reported the following error:
Error:(3, 32) java: 无法访问org.springframework.boot.SpringApplication
错误的类文件: /C:/Users/zxy/.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
请删除该文件或确保该文件位于正确的类路径子目录中。
2. Analysis errors
In the error message, the (wrong) class file version refers to java class file version
.
According to the path of the above error message /C:/Users/zxy/.m2/repository/org/springframework/boot/spring-boot/3.1.0/spring-boot-3.1.0.jar
, find it /spring-boot-3.1.0.jar
, as shown in the following figure:
Copy spring-boot-3.1.0.jar
to the desktop and unzip the jar
package as spring-boot-3.1.0
a folder at the same time:
Open spring-boot-3.1.0
the folder, find org\springframework\boot
the directory, and use Windows PowerShell
to enter the directory:
If you haven't installed it yet Windows PowerShell
, you can click the tutorial on installing powershell on Windows .
We use the class file version number for javap -v SpringApplication.class
viewing .SpringApplication.class
But before viewing, Windows PowerShell
the buffer size needs to be increased.
Right-click Windows PowerShell
the upper left corner of the screen, select properties, find the layout, and select the height of the screen buffer size, as shown in the following figure:
The default buffer size is 3000
, which I set 9000
.
Because SpringApplication.class
the number of bytes of the class file information exceeds the default buffer size, the complete class file information cannot be viewed.
Use the version number of the javap -v SpringApplication.class
viewed SpringApplication.class
class file, as shown in the following figure:
As can be seen from the figure, SpringApplication.class
the class file version is 61
, and the corresponding java
version is 17
.
Check out my jdk
version, pictured below:
My jdk
version is , and 8
my SpringApplication
class files require jdk
.17
Therefore, my jdk
version is too low, and I can only lower SpringApplication
the version to adapt to my jdk
version.
java
jdk
There is a corresponding relationship between the version number of the class file and the version number, such as 61.0
corresponding jdk17
, 52.0
corresponding jdk8
.
The complete correspondence is shown in the table below:
Java version number | java class file version |
---|---|
20 | 64 |
19 | 63 |
18 | 62 |
17 | 61 |
16 | 60 |
15 | 59 |
14 | 58 |
13 | 57 |
12 | 56 |
11 | 55 |
10 | 54 |
9 | 53 |
8 | 52 |
7 | 51 |
6 | 50 |
5 | 49 |
1.4 | 48 |
1.3 | 47 |
1.2 | 46 |
1.1 | 45 |
1.0.2 | 45 |
The complete correspondence can be found in: The class File Format
3. Fix bugs
As my jdk
version is 8
, cannot support what is jdk
required .17
SpringApplication
Therefore, you can only reduce SpringApplication
the version to adapt to my jdk
version.
For our modified SpringApplication
version, we only need to modify the value under the label pom.xml
in the file .<parent>
<version>
Under my original label spring boot
, as shown in the following code:<parent>
<version>
3.1.0
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Now modify <parent>
the label under the<version>
2.6.0
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Look <parent>
under the tab <version>
for 2.6.0
versions SpringApplication.class
.
Find the package C:\Users\你的电脑名字\.m2\repository\org\springframework\boot\spring-boot\2.6.0
in the directory spring-boot-2.6.0.jar
, copy it to the desktop, and decompress it into spring-boot-2.6.0
a folder.
In Windows PowerShell
, use cd C:\Users\zxy\Desktop\spring-boot-2.6.0\org\springframework\boot
the command to enter spring-boot-2.6.0
the folder and execute the following command:
The version of the class file <parent>
under the label is , and the corresponding version is , which matches <version>
the version I currently install .2.6.0
SpringApplication.class
52
jdk
8
jdk
At this point, restart the project and it will run successfully, as shown in the following figure:
4. Error Summary
This error is generally reported: cannot be accessed org.springframework.boot.SpringApplication
, the class file has the wrong version xxx, it should be xxx, please delete the file or ensure that the file is located in the correct class path subdirectory.
The reason is that your version is inconsistent spring boot
with your version. The solution is as follows:jdk
-
Modify your
jdk
version to adapt to yourspring boot
version, which is generally impossible. -
Modify your
spring boot
version, adapt yourjdk
version, and often use this method.