相关推荐recommended
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Context
作者:mmseoamin日期:2024-04-27

问题描述

在运行单元测试报错

java.lang.IllegalStateException: 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 @Context,第1张


原因分析:

1. 没有启动类

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

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


解决方案:

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

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

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

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