springboot测试类时注入对象为NullPointerException

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

解决方法:

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

@RunWith(SpringRunner.class)

@SpringBootTest(classes = BootApplication.class)

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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2021-08-11
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
相关资源
相似解决方案