# Spring Boot 进行测试提示 TestContextAnnotationUtils 错误

**URL:** <https://www.isharkfly.com/t/spring-boot-testcontextannotationutils/13208>\
**Category:** 程序语言\
**Tags:** java, spring\
**Created:** [January 25, 2021, 6:25pm UTC](https://www.isharkfly.com/t/spring-boot-testcontextannotationutils/13208 "2021-01-25T18:25:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 25, 2021, 6:25pm UTC](https://www.isharkfly.com/t/spring-boot-testcontextannotationutils/13208/1 "2021-01-25T18:25:35Z")

</div>

在 Spring Boot 运行测试的时候提示错误：

```auto
java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils

```

![spring-boot-test-01](https://www.isharkfly.com/images/transparent.png)

## 问题和解决办法

出现上面的问题是因为我们将 Spring Boot 从版本 2.3.3 升级到了 2.4

在依赖 spring-test 中，我们还是定义 5.2.8.RELEASE 了这个版本。

```auto
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.2.8.RELEASE</version>
            <scope>test</scope>
        </dependency>

```

如果升级版本到 Spring Boot 2.4 的版本的话，你可以首先取消掉 5.2.8.RELEASE 这个版本的限制。

如果取消掉版本的话，你可以看到 Spring 的测试使用的是 5.3.1 的版本。

![spring-boot-test-02](https://www.isharkfly.com/images/transparent.png)

上面的错误信息就是因为版本的不同，如果你升级了 Spring Boot 的话，相应的测试版本也需要升级。

当取消掉版本后，再次运行测试。

![spring-boot-test-03](https://www.isharkfly.com/images/transparent.png)

通过控制台测试就可以看到版本兼容性问题已经解决没有了。
