解决Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

报错信息:

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

原因:在我项目中,出现如上报错的原因是因为我的测试类直接放在了java目录下,没有包。测试方法在运行的时候,需要寻找到SpringBoot启动类,默认情况下会直接在当前包路径上寻找

报错时的项目结构

解决方法:

​ 1. 修改项目结构将测试方法放在与SpringBoot启动类相同的包下

移动测试类到top.likeqc包下

​ 2. 使用 @SpringBootTest(classes = MybatisPlusApplication.class)注解指定SpringBoot启动类

参考:junit启动报错 Unable to find a @SpringBootConfiguration

posted @ 2021-03-12 15:52  likeqc  阅读(7336)  评论(0)    收藏  举报