Spring boot 将Spring Boot升级到2.4.2时,org.springframework.test.context.TestContextAnnotationUtils上的ClassNotFoundException

Spring boot 将Spring Boot升级到2.4.2时,org.springframework.test.context.TestContextAnnotationUtils上的ClassNotFoundException,spring-boot,junit5,spring-test,Spring Boot,Junit5,Spring Test,在我的POM中,我将Spring Boot的版本从2.3.5.RELEASE升级到了2.4.2。因此,mvn清洁测试现在失败并出现错误 java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.TestContextA

在我的POM中,我将Spring Boot的版本从2.3.5.RELEASE升级到了2.4.2。因此,
mvn清洁测试现在失败并出现错误

java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils
Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.TestContextAnnotationUtils
在一个简单的测试中

package ch.ge.ael.enu.mediation;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class MediationApplicationTests {

    @Test
    void contextLoads() {
    }

}

有人有线索吗?

似乎您缺少依赖项。从spring-boot-starter-test-2.4.2引用的类org.springframework.test.context.TestContextAnnotationUtils位于

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.3.3</version>
    </dependency>

org.springframework
spring上下文
5.3.3

所描述的问题与不同Maven依赖项之间的冲突有关。我们在尝试使用最新版本的Spring Boot时遇到了同样的问题

在分析依赖关系树和依赖关系列表之后,您可能会得到版本即将过期的依赖关系。尝试从那里排除,并包括作为独立的,这有助于我们获得同步

Maven命令:

mvn dependency:tree
mvn dependency:list

Marten Deinum的评论是正确的:一个依赖项在Spring jar的版本中造成了巨大的破坏。对于Camel 3.6.0,Spring Boot 2.3.5.RELEASE正常,但Spring Boot 2.4.2不正常。将Camel升级到3.7.1成功。

从2.4.0版开始,.RELEASE标签将不再使用。查看Spring博客,了解以下详细信息:

解决此问题的方法是将我的
Spring测试
依赖项版本从
5.2.9升级。将
发布到
5.3.8

通常,您的测试jar已损坏,或者正在混合来自不同版本Spring的jar。我怀疑是后者,您正试图通过提供不必要的依赖项或版本标记来智取框架。本文可能会有所帮助。显示您的pom.xml。没有这些,帮助只不过是猜测而已。非常感谢@M.Deinum,你的干预措施和十年前一样有用!