在一个测试类中使用
@RunWith(SpringRunner.class)
@SpringBootTest
public class SuiSiteJob {
@Autowired
SiteService siteService;
@Autowired
SystemConfigService systemConfigService;
.......
}
由于之前没有用到框架 就直接写在了主函数中
public static void main(String[] args) throws Exception {
SiteJob siteJob = new SiteJob();
File newSite = new File("D:/ssrTask/newToolExcel.txt");
List<String> readLines = FileUtils.readLines(newSite, "utf-8");
for (String line : readLines) {
try {
//去掉标识
if (line.startsWith("\uFEFF")) {//* string = string.substring(1); *//*
line = line.replace("\uFEFF", "");
}
//任务1
siteJob.tempJob(line);
} catch (IOException e) {
e.printStackTrace();
}
}
//任务2
siteJob.downloadJob();
}
后来因为需要使用框架 则移到了Junit Test中
@Test
public void.....{
/*代码同上*/}
启动了之后发现注入的在最开始可以正常注入 但是到我调用的地方就变为了null
经排查 发现我忘记改动代码 SiteJob s = new SiteJob();
在这一行 本被注入好各种属性与类的siteJob 被我重新new了一下 所以就出现了注入的类都为null
改为:删除new语句 函数直接调用 成功解决
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有