Spring boot 启动报错 Unsupported major.minor version 52.0

时间:2022-04-03 17:06:20

Spring boot 启动报错 Unsupported major.minor version 52.0

  • 问题描述
    在创建spring boot hello world 工程时候启动报错, Unsupported major.minor version 52.0。
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/yf/springboot/Application : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

  • 工程描述
    pom文件如下:
<?xml version="1.0" encoding="UTF-8"?>  
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.yf.springboot</groupId>
<artifactId>spring-boot-hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- <version>1.4.0.BUILD-SNAPSHOT</version> -->
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.7</java-version>
</properties>

<!-- Add typical dependencies for a web application -->
<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 不需要version 会根据parent版本进行添加上-->
</dependency>
<!-- 添加fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>

</dependencies>

<!-- Package as an executable jar -->
<build>

<!--
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
-->

<!-- 在这里添加springLoader plugin 实现热拔插开发 1、spring-boot:run
2、run as -java application
run-config vm -javaagent:.\lib\springloaded-1.2.3.RELEASE.jar -noverify
-->

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.3.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>

</executions>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>

<!-- Add Spring repositories -->
<!-- (you don't need this if you are using a .RELEASE version) -->
<!-- <repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories> -->

</project>

Spring boot 启动报错 Unsupported major.minor version 52.0

最后根据报错描述,和网上了解,出错是因为Spring boot 版本的许多jar包 依赖JDK1.8,所以启动时候会报错,类似不支持jdk版本的提示。只要换上JDK8 环境就可以啦。

因为本人Eclipse 是最新版本的依赖jdk1.8,所以不需要安装jdk8。所以再eclipse更还jre换班即可。
更换操作如下:
1、build path

Spring boot 启动报错 Unsupported major.minor version 52.0

2、add library
Spring boot 启动报错 Unsupported major.minor version 52.0

3、select jdk version
Spring boot 启动报错 Unsupported major.minor version 52.0

4、maven update - 重新编译项目
Spring boot 启动报错 Unsupported major.minor version 52.0

经过上诉步骤操作,成功启动spring boot hello world 程序。