Home > Enterprise >  java: class file has wrong version 61.0, should be 55.0
java: class file has wrong version 61.0, should be 55.0

Time:12-07

I'm working with maven with Java 11 and Maven on IntelliJ IDEA.

I'm trying create a JsonTset class like you can see in the screenshot: enter image description here

but build is failing on the below imports:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

with the error:

java: cannot access org.springframework.beans.factory.annotation.Autowired
  bad class file: /C:/Users/<username>/.m2/repository/org/springframework/spring-beans/6.0.2/spring-beans-6.0.2.jar!/org/springframework/beans/factory/annotation/Autowired.class
    **class file has wrong version 61.0, should be 55.0**
    Please remove or make sure it appears in the correct subdirectory of the classpath.

I understand it related to Java versions but can't find any working solution.

Using Java 11 which set in JAVA_HOME.

What I have tried:

  1. update JDK to Java 11.
  2. java -version gives: openjdk version "11.0.17" 2022-10-18 LTS
  3. update the project in IntelliJ to work with Java 11.
  4. remove .idea folder.
  5. invalidate caches

Does someone have any idea how to fix the confusing version?

CodePudding user response:

You're using Spring Framework 6, and since Spring 6, the minimum supported Java version is Java 17 (the class version 61 is the class version of Java 17).

As documented in the Spring Framework Overview for Spring 6:

As of Spring Framework 6.0, Spring requires Java 17 .

So, if you want to use Spring 6, you need to upgrade to Java 17. If you want to continue using Java Java 11, you need to downgrade to Spring 5.3.

CodePudding user response:

Maybe its because of inconsistency between Java version and Spring or Spring Boot. Check your version of Spring. Here is a snippet from the Spring site:

We are planning to release Spring Boot 3.0 in November 2022. This next major revision will be based on Spring Framework 6.0 and will require Java 17 or above. It will also be the first version of Spring Boot that makes use of Jakarta EE 9 APIs (jakarta.) instead of EE 8 (javax.).

https://spring.io/blog/2022/05/24/preparing-for-spring-boot-3-0

  • Related