单元测试,使用 @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);
    }

 

posted @ 2022-09-19 16:33  BBS_自律  阅读(651)  评论(0)    收藏  举报