测试类
1.使用junit依赖 需要加入@RunWith(SpringRunner.class)
Springboot的@RunWith(SpringRunner.class)注解的意义在于Test测试类要使用注入的类,比如@Autowired注入的类,有了@RunWith(SpringRunner.class)这些类才能实例化到spring容器中,自动注入才能生效,否则会报NullPointerExecption错误
2. 使用spring-boot-starter-test依赖可以不用加@RunWith(SpringRunner.class)
spring boot项目错误记录1:测试类报错
最新推荐文章于 2024-06-12 12:15:11 发布