解决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启动类相同的包下

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

浙公网安备 33010602011771号