美文网首页
SpringBoot 测试类 空指针异常

SpringBoot 测试类 空指针异常

作者: 一曲三月 | 来源:发表于2021-12-09 11:19 被阅读0次

1,could not resolve autowired
@Autowired 换成 @Resource
类上添加 @RunWith(SpringRunner.class)
@RunWith(SpringRunner.class) 能使@Resource 标注的类实例化到spring容器中,自动注入才能生效
@SpringBootTest 当测试类的包名和启动类的包名不一致时,可以指定启动类。

相关文章

网友评论

      本文标题:SpringBoot 测试类 空指针异常

      本文链接:https://www.haomeiwen.com/subject/mnhffrtx.html