Spring Boot -Class file has wrong version 61.0, should be 52.0


you might be facing the below exception in the recent versions of Spring boot that class file has wrong version 61.0, should be 52.0

Exception:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project spring-api-gateway-demo: Compilation failure
[ERROR] /D:/sts/workspace/spring-api-gateway-demo/src/main/java/com/javasavvy/apigateway/SpringApiGatewayDemoApplication.java:[3,32] cannot access org.springframework.boot.SpringApplication
[ERROR]  bad class file: C:\Users\jayaramp.m2\repository\org\springframework\boot\spring-boot.0.4\spring-boot-3.0.4.jar(org/springframework/boot/SpringApplication.class)
[ERROR]  class file has wrong version 61.0, should be 52.0
[ERROR]  Please remove or make sure it appears in the correct subdirectory of the classpath.

Solution:

Spring Boot 3.0 does not support java 1.8 and requires minimum version of Java 17.0.

The following are possible reasons and please try to fix if your spring boot configurations matches any one:

  1. Your eclipse or STS JDK version is 1.8 and you are using Spring Boot 3.0. The solution is to upgrade or configure JDK to 17.0 in your STS to fix the issue
  2. You are using JDK 1.8 but configuring Spring cloud to 4.x which requires 17.0. The solution is if you are going to stick with JDK 1.8 and lower than 17 then configure Spring Cloud jars to 3.x
  3. Check Eclipse or STS compiler version.
    1. If you are using Spring boot 3.0 then compiler should be 17
    2. If you are using spring boot 2.x.x versions then check maven dependencies for spring boot and cloud both.
<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>2021.0.5</spring-cloud.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-gateway</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
As shown in above pic, Configure Spring cloud versions compatible with Spring Boot versions.
Note: Spring Cloud Dalston, Edgware, Finchley, and Greenwich have all reached end of life status and are no longer supported

Thanks.