Springboot test无法启动 Springboot使用test无法启动问题的解决

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Springboot test无法启动 Springboot使用test无法启动问题的解决

weixin_44202031   2021-10-14 我要评论
想了解Springboot使用test无法启动问题的解决的相关内容吗,weixin_44202031在本文为您仔细讲解Springboot test无法启动的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Springboot,test,test无法启动,下面大家一起来学习吧。

Springboot使用test无法启动

test无法启动,遇到

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use报错信息

测试文件和启动文件是否才同一层目录下

在这里插入图片描述

SpringBootTest--踩坑错误

Spring boot降低了我们对spring开发的难度

采用了大量在的自动配置,我们只需要进行简单的基本配置,就能快速开发一个spring应用。

同样spring对于单元测试也有场景启动器----spring-boot-starter-test,可以让我们在,spring环境下进行测试。

昨天测试的时候,容器都无法启动,检查之后发现了原因,也是因为自己粗心大意。

@RunWith(value = SpringRunner.class)
//@SpringBootTest(classes = SearchApplication9007Test.class)   //错误写法 ,这个class应该填写的是你的主启动类,
                  //而不是你的测试类。以为之前用的稍微高点的版本,可以省略这个括
                  //号内的配置。但是这个版本需要配置
                  
@SpringBootTest(classes = SearchApplication9007.class)     //正确写法 ,应该填入主配置类
public class SearchApplication9007Test{
    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;
    /**

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们