好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Springboot使用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环境下进行测试。

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

?

1

2

3

4

5

6

7

8

9

10

@RunWith (value = SpringRunner. class )

//@SpringBootTest(classes = SearchApplication9007Test.class)   //错误写法 ,这个class应该填写的是你的主启动类,

                   //而不是你的测试类。以为之前用的稍微高点的版本,可以省略这个括

                   //号内的配置。但是这个版本需要配置

                  

@SpringBootTest (classes = SearchApplication9007. class )     //正确写法 ,应该填入主配置类

public class SearchApplication9007Test{

     @Autowired

     private ElasticsearchTemplate elasticsearchTemplate;

     /**

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

原文链接:https://blog.csdn.net/weixin_44202031/article/details/104827145

查看更多关于Springboot使用test无法启动问题的解决的详细内容...

  阅读:13次