springboot测试类测试时注入的对象为null

springboot测试类时注入对象为NullPointerException

解决方法:

正常来说测试类加上以下配置就可以正常@Test测试,但@SpringBootTest(classes = BootApplication.class)中的classes的值要纸箱启动类的才可以正常注入属性。也就是说BootApplication是springboot启动类

@RunWith(SpringRunner.class)

@SpringBootTest(classes = BootApplication.class)

愿你眼中有光芒,活成你想要的模样
原文地址:https://www.cnblogs.com/SmallStrange/p/14368673.html