1,could not resolve autowired
@Autowired 换成 @Resource
类上添加 @RunWith(SpringRunner.class)
@RunWith(SpringRunner.class) 能使@Resource 标注的类实例化到spring容器中,自动注入才能生效
@SpringBootTest 当测试类的包名和启动类的包名不一致时,可以指定启动类。
1,could not resolve autowired
@Autowired 换成 @Resource
类上添加 @RunWith(SpringRunner.class)
@RunWith(SpringRunner.class) 能使@Resource 标注的类实例化到spring容器中,自动注入才能生效
@SpringBootTest 当测试类的包名和启动类的包名不一致时,可以指定启动类。
本文标题:SpringBoot 测试类 空指针异常
本文链接:https://www.haomeiwen.com/subject/mnhffrtx.html
网友评论