简体   繁体   English

java: class 文件版本错误 61.0,应该是 55.0

[英]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:我试过的:

  1. update JDK to Java 11.将 JDK 更新为 Java 11.
  2. java -version gives: openjdk version "11.0.17" 2022-10-18 LTS java -version 给出:openjdk 版本“11.0.17”2022-10-18 LTS
  3. update the project in IntelliJ to work with Java 11.更新 IntelliJ 中的项目以使用 Java 11。
  4. remove.idea folder.删除.idea 文件夹。
  5. invalidate caches使缓存无效

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

to use version 11, if your project was created with version 17, change in pom.xml adj reference image要使用版本 11,如果您的项目是使用版本 17 创建的,请更改 pom.xml adj 参考图像

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 class文件版本55.0错误,应该是52.0 - Class file has wrong version 55.0, should be 52.0 类文件有错误的版本 55.0,应该是 52.0 (IntelliJ) - Class file has wrong version 55.0, should be 52.0 (IntelliJ) VSCode Java Project:类文件的版本为55.0,应为52.0,Gradle Build Failing - VSCode Java Project: Class file has wrong version 55.0, should be 52.0, Gradle Build Failing 构建 Alfresco 时出现错误“类文件的版本 55.0 错误,应为 52.0” - error "class file has wrong version 55.0, should be 52.0" when building Alfresco 谷歌云平台中的“类文件版本错误 55.0,应为 53.0” - 'class file has wrong version 55.0, should be 53.0' in Google Cloud platform UnsupportedClassVersionError: 已由较新版本的 Java Runtime(类文件版本 55.0)编译,此版本 (..) 高达 52.0 - UnsupportedClassVersionError: has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version (..)up to 52.0 org/testng/ITestListener 已由更新版本的 Java 运行时(类文件版本 55.0)编译,最多只能识别 52 版本 - org/testng/ITestListener has been compiled by a more recent version of the Java Runtime (class file version 55.0), only recognizes version up to 52 无法编译Java代码-“类文件的版本错误为52.0,应为48.0” - Cannot compile Java code - “class file has wrong version 52.0, should be 48.0” 类文件有错误的版本xxx,应该是xxx - Class file has wrong version xxx, should be xxx 并行处理:类文件的版本为49.0,应为48.0 - parallel processing: class file has wrong version 49.0, should be 48.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM