单元测试,使用 @Resource 或 @Autowired注入的对象为空,解决办法
单元测试,@Resource无法注入
解决代码 测试类的写法:
@RunWith(SpringRunner.class) @SpringBootTest(classes = {LreApplication.class}) public class Line { @Resource private GanSuComputeImpl ganSuCompute; @Resource private ProjectService projectService; @Test public void testComputeLine() { String projectName = projectService.getProjectName(); System.out.println(projectName); }