Spring Boot 进行测试提示 TestContextAnnotationUtils 错误
2023-09-27 14:20:31 时间
在 Spring Boot 运行测试的时候提示错误:
java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils
问题和解决办法
出现上面的问题是因为我们将 Spring Boot 从版本 2.3.3 升级到了 2.4
在依赖 spring-test 中,我们还是定义 5.2.8.RELEASE 了这个版本。
<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 的话,相应的测试版本也需要升级。
当取消掉版本后,再次运行测试。
通过控制台测试就可以看到版本兼容性问题已经解决没有了。
https://www.ossez.com/t/spring-boot-testcontextannotationutils/13208
相关文章
- 网络编程 -- RPC实现原理 -- RPC -- 迭代版本V4 -- 远程方法调用 整合 Spring 自动注册
- 一点一点学架构(四)—Spring.NET错误Cannot Resolve Type……
- Spring Boot 之 RESTfull API简单项目的快速搭建(三)
- Spring CORS
- Spring Boot反爬虫,防止接口盗刷
- 使用spring等框架的web程序在Tomcat下的启动顺序及思路理清
- 基于Java(Spring boot+Hibernate)+VUE+MySQL实现(Web)员工信息管理系统【100010234】
- cxf整合spring错误为:cvc-complex-type.2.4.c
- Manual close is not allowed over a Spring managed SqlSession(转)
- 【Spring常见错误】java.lang.NoClassDefFoundError: redis/clients/jedis/UnifiedJedis
- 【Spring常见错误】Initialization failed for ‘https://start.spring.io‘
- Spring中@Primary注解
- Spring_错误 java.sql.SQLException: Lock wait timeout exceeded | CannotAcquireLockException 的解决
- Spring Boot 集成 easypoi实现excel的导入导出、excel导入导出含图片
- 玩转spring boot——结合docker