[Exception solution] java: cannot access the solution of org.springframework.boot.SpringApplication

This article directory

1. Background description

2. The reason for the error

3. Solutions


1. Background description

Spring official website: Spring | Home

Initialize a new SpringBoot project through the Spring official website , as shown in the figure below.

Key information: maven project, Java language, SpringBoot version number, project information, packaging method, Java version , and then click GENERATE CTRL + Enter on the far left below to generate a SpringBoot project.

After downloading, use IDEA to open it, download the maven dependencies, select Java8 for the JDK version (the local computer only has one Java1.8), and no error is reported. After starting the project, the result fails to start, and the error message is as follows:

java: 无法访问org.springframework.boot.SpringApplication
  错误的类文件: /D:/Repository/org/springframework/boot/spring-boot/3.0.5/spring-boot-3.0.5.jar!/org/springframework/boot/SpringApplication.class
    类文件具有错误的版本 61.0, 应为 52.0
    请删除该文件或确保该文件位于正确的类路径子目录中。

In theory, a project initialized from the Spring official website does not add any code and should not report an error. However, in fact, an error message appears inexplicably.

2. The reason for the error

The class file version mentioned in the error message refers to the java class file version, the java class file version. In fact, there is a corresponding relationship between this version number and the jdk version number. Specifically, 61.0 corresponds to jdk17, and 52.0 corresponds to jdk8.
For the complete correspondence, see: https://stackoverflow.com/questions/9170832/list-of-java-class-file-format-major-version-numbers , access may be slower, I have taken a screenshot, see the picture below Can.

 The above error is mainly caused by the mismatch between the class file version and the JDK version number. Solving this problem is very simple, just match the relationship between the two.

3. Solutions

There are two solutions: one is to reduce the version number of the class file (that is, reduce the SpringBoot version number), and the other is to increase the JDK version number .

Take the SpringBoot project I initialized by myself as an example. The SpringBoot version I chose is 3.0.5. The JDK version required by this version of SpringBoot is JDK17, and my local computer only has a JDK8 operating environment installed, so I will report this. mistake.

Check the SpringBoot version number from the Spring official website, check the address: https://spring.io/projects/spring-boot#support , after reducing the version number, the project starts normally and successfully. I chose 2.1.5.RELEASE.

end!

Guess you like

Origin blog.csdn.net/weixin_44299027/article/details/129820807