高版本的spring-context不能用junit

问题遇到的现象和发生背景

为什么高版本的spring-context不能用junit,在低版本中可以正常使用

遇到的现象和发生背景,请写出第一个错误信息

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests


Caused by: org.junit.platform.commons.JUnitException: ClassSelector [className = 'spring.TestIOC'] resolution failed
Caused by: java.lang.UnsupportedClassVersionError: org/springframework/context/ApplicationContext has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0 ![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/331951318276123.png "#left")

img

img

<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.3.1</version>
</dependency>

在5.几的版本下就可以,而6.几的版本都不行

  • 首先要看你的junit版本是啥, 从下面这个报错看,是 JDK版本不适配,编译的版本是 61【JDK17】, 运行环境却是 55【JDK11】

Caused by: java.lang.UnsupportedClassVersionError: org/springframework/context/ApplicationContext has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • JDK版本和字节码版本关系

    img