SpringBoot启动异常之Exception in thread “main“ java.lang.UnsupportedClassVersionError

异常提示:Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

 一、完整错误报文(两种)

1.1 启动异常之UnsupportedClassVersionError

Exception in thread "main" java.lang.UnsupportedClassVersionError: 
org/springframework/boot/SpringApplication has been compiled by a 
more recent version of the Java Runtime (class file version 61.0), 
this version of the Java Runtime only recognizes class file 
versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at com.handlefile.Application.main(Application.java:10)

1.2 启动异常之启动类无法访问

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

二、错误原因 

 SpringBoot 与 JDK 版本冲突:新建项目时,idea 会默认选择更高的 SpringBoot 版本,但>3.0SpringBoot 的版本暂不支持 JDK1.8,所以会出现启动报错

一般来说高JDK版本能向下兼容低版本的springboot版本。

建议在springboot 2.5.x及其之前使用JDK8,之后的springboot版本使用JDK11即可

三、解决方案

在pom.xml文件中修改SpringBoot版本或JDK版本

 四、简要介绍SpringBoot版本与JDK版本对应关系

SpringBoot版本 JDK最低版本 SpringBoot官网证据
1.0.0.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.0.1.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.0.2.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.0.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.1.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.2.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.3.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.4.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.5.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.6.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.7.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.8.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.9.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.10.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.11.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.1.12.RELEASE 1.6 Regardless, you will need Java SDK v1.6 or higher.
1.2.0.RELEASE 1.6 Spring Boot 1.2.0.RELEASE requires Java 6 and Spring Framework 4.1.3 or above.
1.2.1.RELEASE 1.6 Spring Boot 1.2.1.RELEASE requires Java 6 and Spring Framework 4.1.3 or above.
1.2.2.RELEASE 1.7 Spring Boot 1.2.2.RELEASE requires Java 7 and Spring Framework 4.1.3 or above.
1.2.3.RELEASE 1.7 Spring Boot 1.2.3.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.2.4.RELEASE 1.7 Spring Boot 1.2.4.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.2.5.RELEASE 1.7 Spring Boot 1.2.5.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.2.6.RELEASE 1.7 Spring Boot 1.2.6.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.2.7.RELEASE 1.7 Spring Boot 1.2.7.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.2.8.RELEASE 1.7 Spring Boot 1.2.8.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.3.0.RELEASE 1.7 Spring Boot 1.3.0.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.3.1.RELEASE 1.7 Spring Boot 1.3.0.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.
1.3.2.RELEASE 1.7

Spring Boot 1.3.0.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.

1.3.3.RELEASE 1.7 Spring Boot 1.3.0.RELEASE requires Java 7 and Spring Framework 4.1.5 or above.

1.3.4.RELEASE

1.7

Spring Boot 1.3.4.RELEASE requires Java 7 and Spring Framework 4.2.6.RELEASE or above.

1.3.5.RELEASE 1.7 Spring Boot 1.3.5.RELEASE requires Java 7 and Spring Framework 4.2.6.RELEASE or above.
1.3.6.RELEASE 1.7 Spring Boot 1.3.6.RELEASE requires Java 7 and Spring Framework 4.2.7.RELEASE or above.
1.3.7.RELEASE 1.7 Spring Boot 1.3.7.RELEASE requires Java 7 and Spring Framework 4.2.7.RELEASE or above.
1.3.8.RELEASE 1.7 Spring Boot 1.3.8.RELEASE requires Java 7 and Spring Framework 4.2.8.RELEASE or above.
1.4.0.RELEASE 1.7 Spring Boot 1.4.0.RELEASE requires Java 7 and Spring Framework 4.3.2.RELEASE or above.
1.4.1.RELEASE 1.7 Spring Boot 1.4.1.RELEASE requires Java 7 and Spring Framework 4.3.3.RELEASE or above.
1.4.2.RELEASE 1.7 Spring Boot 1.4.2.RELEASE requires Java 7 and Spring Framework 4.3.4.RELEASE or above.
1.4.3.RELEASE 1.7 Spring Boot 1.4.3.RELEASE requires Java 7 and Spring Framework 4.3.5.RELEASE or above.
1.4.4.RELEASE 1.7 Spring Boot 1.4.4.RELEASE requires Java 7 and Spring Framework 4.3.6.RELEASE or above.
1.4.5.RELEASE 1.7 Spring Boot 1.4.5.RELEASE requires Java 7 and Spring Framework 4.3.7.RELEASE or above.
1.4.6.RELEASE 1.7 Spring Boot 1.4.6.RELEASE requires Java 7 and Spring Framework 4.3.8.RELEASE or above.
1.4.7.RELEASE 1.7 Spring Boot 1.4.7.RELEASE requires Java 7 and Spring Framework 4.3.9.RELEASE or above.
1.5.0.RELEASE 1.7 Spring Boot 1.5.0.RELEASE requires Java 7 and Spring Framework 4.3.6.RELEASE or above.
1.5.1.RELEASE 1.7 Spring Boot 1.5.1.RELEASE requires Java 7 and Spring Framework 4.3.6.RELEASE or above.
1.5.2.RELEASE 1.7 Spring Boot 1.5.2.RELEASE requires Java 7 and Spring Framework 4.3.7.RELEASE or above.
1.5.3.RELEASE 1.7 Spring Boot 1.5.3.RELEASE requires Java 7 and Spring Framework 4.3.8.RELEASE or above.
1.5.4.RELEASE 1.7 Spring Boot 1.5.4.RELEASE requires Java 7 and Spring Framework 4.3.9.RELEASE or above.
1.5.5.RELEASE 1.7 Spring Boot 1.5.5.RELEASE requires Java 7 and Spring Framework 4.3.10.RELEASE or above.
1.5.6.RELEASE 1.7 Spring Boot 1.5.6.RELEASE requires Java 7 and Spring Framework 4.3.10.RELEASE or above.
1.5.7.RELEASE 1.7 Spring Boot 1.5.7.RELEASE requires Java 7 and Spring Framework 4.3.11.RELEASE or above.
1.5.8.RELEASE 1.7 Spring Boot 1.5.8.RELEASE requires Java 7 and Spring Framework 4.3.12.RELEASE or above.
1.5.9.RELEASE 1.7 Spring Boot 1.5.9.RELEASE requires Java 7 and Spring Framework 4.3.13.RELEASE or above.
1.5.10.RELEASE 1.7 Spring Boot 1.5.10.RELEASE requires Java 7 and Spring Framework 4.3.14.RELEASE or above.
1.5.11.RELEASE 1.7 Spring Boot 1.5.11.RELEASE requires Java 7 and Spring Framework 4.3.15.RELEASE or above.
1.5.12.RELEASE 1.7 Spring Boot 1.5.12.RELEASE requires Java 7 and Spring Framework 4.3.16.RELEASE or above.
1.5.13.RELEASE 1.7 Spring Boot 1.5.13.RELEASE requires Java 7 and Spring Framework 4.3.17.RELEASE or above.
1.5.14.RELEASE 1.7 Spring Boot 1.5.14.RELEASE requires Java 7 and Spring Framework 4.3.18.RELEASE or above.
1.5.15.RELEASE 1.7 Spring Boot 1.5.15.RELEASE requires Java 7 and Spring Framework 4.3.18.RELEASE or above.
1.5.16.RELEASE 1.7 Spring Boot 1.5.16.RELEASE requires Java 7 and Spring Framework 4.3.19.RELEASE or above.
1.5.17.RELEASE 1.7 Spring Boot 1.5.17.RELEASE requires Java 7 and Spring Framework 4.3.20.RELEASE or above.
1.5.18.RELEASE 1.7 Spring Boot 1.5.18.RELEASE requires Java 7 and Spring Framework 4.3.21.RELEASE or above.
1.5.19.RELEASE 1.7 Spring Boot 1.5.19.RELEASE requires Java 7 and Spring Framework 4.3.22.RELEASE or above.
1.5.20.RELEASE 1.7 Spring Boot 1.5.20.RELEASE requires Java 7 and Spring Framework 4.3.23.RELEASE or above.
1.5.21.RELEASE 1.7 Spring Boot 1.5.21.RELEASE requires Java 7 and Spring Framework 4.3.24.RELEASE or above.
2.0.0.RELEASE 1.8 Spring Boot 2.0.0.RELEASE requires Java 8 or 9 and Spring Framework 5.0.4.RELEASE or above.
2.0.1.RELEASE 1.8 Spring Boot 2.0.1.RELEASE requires Java 8 or 9 and Spring Framework 5.0.5.RELEASE or above.
2.0.2.RELEASE 1.8 Spring Boot 2.0.2.RELEASE requires Java 8 or 9 and Spring Framework 5.0.6.RELEASE or above.
2.0.3.RELEASE 1.8 Spring Boot 2.0.3.RELEASE requires Java 8 or 9 and Spring Framework 5.0.7.RELEASE or above.
2.0.4.RELEASE 1.8 Spring Boot 2.0.4.RELEASE requires Java 8 or 9 and Spring Framework 5.0.8.RELEASE or above.
2.0.5.RELEASE 1.8 Spring Boot 2.0.5.RELEASE requires Java 8 or 9 and Spring Framework 5.0.9.RELEASE or above.
2.0.6.RELEASE 1.8 Spring Boot 2.0.6.RELEASE requires Java 8 or 9 and Spring Framework 5.0.10.RELEASE or above.
2.0.7.RELEASE 1.8 Spring Boot 2.0.7.RELEASE requires Java 8 or 9 and Spring Framework 5.0.11.RELEASE or above.
2.0.8.RELEASE 1.8 Spring Boot 2.0.8.RELEASE requires Java 8 or 9 and Spring Framework 5.0.12.RELEASE or above.
2.0.9.RELEASE 1.8 Spring Boot 2.0.9.RELEASE requires Java 8 or 9 and Spring Framework 5.0.13.RELEASE or above.
2.1.0.RELEASE 1.8 Spring Boot 2.1.0.RELEASE requires Java 8 or 9 and Spring Framework 5.1.2.RELEASE or above.
2.1.1.RELEASE 1.8 Spring Boot 2.1.1.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.3.RELEASE or above is also required.
2.1.2.RELEASE 1.8 Spring Boot 2.1.2.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.4.RELEASE or above is also required.
2.1.3.RELEASE 1.8 Spring Boot 2.1.3.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.5.RELEASE or above is also required.
2.1.4.RELEASE 1.8 Spring Boot 2.1.4.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.6.RELEASE or above is also required.
2.1.5.RELEASE 1.8 Spring Boot 2.1.5.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.7.RELEASE or above is also required.
2.1.6.RELEASE 1.8 Spring Boot 2.1.6.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.8.RELEASE or above is also required.
未完,待续...

猜你喜欢

转载自blog.csdn.net/weixin_52255395/article/details/128639487