java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Context

问题描述

在运行单元测试报错:

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


原因分析:

1. 没有启动类

2. 没有加载到启动类 -无法找到@SpringBootConfiguration

3. 测试类包名,调整到和启动类一致即可。


解决方案:

1. 在@SpringBootTest添加启动类,配置启动类

2. 添加@ContextConfiguration注解,配置启动类