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


springboot测试类时注入对象为NullPointerException

解决方法:

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

@RunWith(SpringRunner.class)

@SpringBootTest(classes = BootApplication.class)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM