I'm working with Maven with Java 11 and Maven on IntelliJ IDEA. I'm trying create a JsonTset class as follows:
import org.junit.BeforeClass;
import org.junit.Test;
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;
import java.io.IOException;
import java.nio.file.Paths;
@JsonTest
public class JacksonInjectExample {
private static final String filePath = "test.json";
private static final String JSON = String.format(String.valueOf(Paths.get(filePath)));
@Autowired
private JacksonTester<OHStepTrackingNotification> jacksonTester;
@Configuration
public static class TestConfiguration {...}
@BeforeClass
static public void setSystemProperties() throws IOException {...}
@Test
public void test() throws IOException {...}
}
But the 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;
It fails 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 this problem is related to Java versions, but I can't find any working solution.
Using Java 11 which is set in JAVA_HOME.
What I have tried:
- Update JDK to Java 11.
java -version
gives:openjdk version "11.0.17" 2022-10-18 LTS
- Update the project in IntelliJ to work with Java 11.
- Remove
.idea
folder. - Invalidate caches
How can I fix the confusing version?