[英]java: class file has wrong version 61.0, should be 55.0
I'm working with maven with Java 11 and Maven on IntelliJ IDEA.我在 IntelliJ IDEA 上使用 maven 和 Java 11 和 Maven。
I'm trying create a JsonTset class like you can see in the screenshot:我正在尝试创建一个 JsonTset class,就像您在屏幕截图中看到的那样:
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.我了解它与 Java 版本相关,但找不到任何有效的解决方案。
Using Java 11 which set in JAVA_HOME.使用JAVA_HOME中设置的Java 11。
What I have tried:我试过的:
Does someone have any idea how to fix the confusing version?有人知道如何修复令人困惑的版本吗?
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).您使用的是 Spring Framework 6,自 Spring 6 起,支持的最低 Java 版本是 Java 17(类版本 61 是 Java 17 的类版本)。
As documented in the Spring Framework Overview for Spring 6:如 Spring 6 的Spring Framework Overview中所述:
As of Spring Framework 6.0, Spring requires Java 17+.从 Spring Framework 6.0 开始,Spring 需要 Java 17+。
So, if you want to use Spring 6, you need to upgrade to Java 17. If you want to continue using Java 11, you need to downgrade to Spring 5.3.所以,如果你想使用Spring 6,你需要升级到Java 17。如果你想继续使用Java 11,你需要降级到Spring 5.3。
Maybe its because of inconsistency between Java version and Spring or Spring Boot.可能是因为 Java 版本与 Spring 或 Spring Boot 不一致。 Check your version of Spring.检查您的 Spring 版本。 Here is a snippet from the Spring site:这是 Spring 网站的一个片段:
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.我们计划在 2022 年 11 月发布 Spring Boot 3.0。下一次重大修订将基于 Spring Framework 6.0,并且需要 Java 17 或更高版本。 It will also be the first version of Spring Boot that makes use of Jakarta EE 9 APIs (jakarta. ) instead of EE 8 (javax. ).它还将是第一个使用 Jakarta EE 9 API (jakarta. ) 而不是 EE 8 (javax. ) 的 Spring Boot 版本。
https://spring.io/blog/2022/05/24/preparing-for-spring-boot-3-0 https://spring.io/blog/2022/05/24/preparing-for-spring-boot-3-0
As of this writing, IntelliJ IDEA automatically uses Spring Boot 3.0 when creating a new Spring Boot project -- even if you specify that it should use an incompatible Java version (ie, earlier than Java 17).在撰写本文时,IntelliJ IDEA 在创建新的 Spring Boot 项目时自动使用 Spring Boot 3.0——即使您指定它应使用不兼容的 Java 版本(即早于 Java 17)。 To use a 2.x version of Spring Boot, you will need to use the Spring Initializer:要使用 2.x 版本的 Spring Boot,您需要使用 Spring Initializer:
https://start.spring.io/ https://start.spring.io/
You can then extract and load this into IntelliJ.然后您可以将其提取并加载到 IntelliJ 中。
I have same issue我有同样的问题
When I create project maven with java version 17当我使用 java 版本 17 创建项目 maven 时
I have issue: Upgrade Module SDK in project settings to 17 or higher I change version SDK to 11我有问题:将项目设置中的模块 SDK 升级到 17 或更高版本我将版本 SDK 更改为 11
after that, I have issue: class file has wrong version 61.0, should be 55.0之后,我有问题:class 文件版本 61.0 错误,应该是 55.0
it is from spring boot 3.0.1它来自 spring 引导 3.0.1
show I have change it to 2.7.3 --> it is ok显示我已将其更改为 2.7.3 --> 没问题
like image: https://drive.google.com/drive/folders/17nZIDj6Hidg6AhR_0DSqi0bADhvSYyLk像图片: https://drive.google.com/drive/folders/17nZIDj6Hidg6AhR_0DSqi0bADhvSYyLk
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.