当前位置 : 主页 > 编程语言 > java >

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

来源:互联网 收集:自由互联 发布时间:2021-11-19
Springboot使用test无法启动 test无法启动,遇到 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use报错信息 测试文件和启动文件是否才同一层目录下 SpringBootTest--踩坑错

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;
    /**

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

上一篇:java学习DongTai被动型IAST工具部署过程
下一篇:没有了
网友评论