Spring Boot 进行测试提示 TestContextAnnotationUtils 错误

吕旷
• 阅读 225

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

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

Spring Boot 进行测试提示 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 进行测试提示 TestContextAnnotationUtils 错误

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

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

Spring Boot 进行测试提示 TestContextAnnotationUtils 错误

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

https://www.ossez.com/t/spring-boot-testcontextannotationutils/13208

点赞
收藏
评论区
推荐文章
Easter79 Easter79
3年前
springboot设置日志级别时报错
配置springboot日志,输出级别为info,运行时报错:Causedby:org.springframework.boot.context.properties.bind.BindException:Failedtobindpropertiesunder'logging.level'tojava.util.Map<jav
Wesley13 Wesley13
3年前
java的gradle项目的基本配置
plugins{id'org.springframework.boot'version'2.1.4.RELEASE'id'java'}applyplugin:'io.spring.dependencymanagement'group'com.exampl
红烧土豆泥 红烧土豆泥
3年前
Spring Boot:jar中没有主清单属性
使用SpringBoot微服务搭建框架时,使用IDEA可以正常运行,但是使用MAVEN打包工具打包成jar后运行时,提示错误:未找到主清单目录。查看pom文件,发现已添加SpringBoot的构建插件xmlorg.springframework.bootspringbootmavenplugin2.4.1
虾米大王 虾米大王
2年前
java代码036
code036.jsp错误处理页错误提示:
Stella981 Stella981
3年前
IntelliJ Idea取消Could not autowire. No beans of 'xxxx' type found的错误提示
1.问题描述在Idea的spring工程里,经常会遇到Couldnotautowire.Nobeansof'xxxx'typefound的错误提示。但程序的编译和运行都是没有问题的,这个错误提示并不会产生影响。但红色的错误提示在有些有强迫症的程序员眼里,多多少少有些不太舒服。!输入图片说明(https://static.o
Wesley13 Wesley13
3年前
VBox 启动虚拟机失败
在Vbox(5.0.8版本)启动Ubuntu的虚拟机时,遇到错误信息:NtCreateFile(\\Device\\VBoxDrvStub)failed:0xc000000034STATUS\_OBJECT\_NAME\_NOT\_FOUND(0retries) (rc101)Makesurethekern
Stella981 Stella981
3年前
Jenkins配置下拉菜单联动效果
  在使用Jenkins集成时,经常需要配置一些环境信息,由于测试、线上、预发布需要切换环境和域名,需要在Jenkins中配置下拉菜单联动效果。  首先选择参数化构建过程,然后首先配置环境,环境分为:测试环境、预发布环境、正式环境,选择的组件为ChoiceParameter,Name定义为environment,选项为test、pre、onli
Stella981 Stella981
3年前
Spring Boot超简单的测试类demo
1概述SpringBoot结合Junit的简单测试类demo,流程是先引入依赖,接着编写测试类测试运行即可。2依赖<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringbootstartert
Stella981 Stella981
3年前
Spring Boot(十一):Spring Boot如何测试打包部署
一、开发阶段(一)单元测试在开发阶段的时候最重要的是单元测试,SpringBoot对单元测试的支持已经很完善了。1、在pom.xml文件中添加依赖<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringb
Stella981 Stella981
3年前
ContextLoaderListener ClassNotFoundException
在初学使用maven构建javaWeb的项目的时候,启动tomcat加载时,总是提示如下错误,辛苦一番终于找到解决办法。严重:Errorconfiguringapplicationlistenerofclassorg.springframework.web.context.ContextLoaderListenerJava(https://
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
吕旷
吕旷
Lv1
此曲只应天上有,人间能得几回闻。
文章
3
粉丝
0
获赞
0