软件编程
位置:首页>> 软件编程>> java编程>> Springboot使用test无法启动问题的解决

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

作者:weixin_44202031  发布时间:2021-07-03 22:09:23 

标签:Springboot,test,无法启动

Springboot使用test无法启动

test无法启动,遇到

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

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

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

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

来源:https://blog.csdn.net/weixin_44202031/article/details/104827145

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com