首页 > 解决方案 > 将 Spring Boot 升级到 2.4.2 时 org.springframework.test.context.TestContextAnnotationUtils 上的 ClassNotFoundException

问题描述

在我的 POM 中,我将 Spring Boot 的版本从 2.3.5.RELEASE 升级到了 2.4.2。结果,mvn clean test现在失败并出现错误

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-bootjunit5spring-test

解决方案


为我解决这个问题的方法是将我的spring-test依赖版本从升级5.2.9.RELEASE5.3.8


推荐阅读