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

Spring Boot单元测试报错!

报错信息:

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张图片

报错原因

测试类和Spring Boot启动类不在一个目录下。

解决办法:

将启动类和测试类放在同一个包下就可以了。
何为同一个包下,即路径名相同即可。
如都在com.xixihaha下

启动类java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Context_第2张图片测试类
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Context_第3张图片

或者给测试类的注解加上@SpringBootTest(classes = {启动类类名.class})

谢谢!

你可能感兴趣的:(Java,java,开发语言)