问题描述
在我的 Spring Boot 项目中,我可以通过 @Scheduled 注释自动运行 REST API:
@Scheduled (fixedDelayString = "$ {fixedRate.in.milliseconds}").
如果我不中断应用程序,它会每 3 分钟正确执行一次 REST 调用:
服务:
@Transactional
@Scheduled(fixedRateString = "${fixedRate.in.milliseconds}")
// @Scheduled(fixedDelayString = "${fixedRate.in.milliseconds}")
public List<MissingDeviceEntity> getAllMissingDeviceEntity() throws Exception {
final String methodName = "getAllMissingDeviceEntity()";
try {
this.startLog(methodName);
logger.info("START");
this.addMMMEntity();
List<MMEntity> MMEs = monterotondoMarittimoDao.getAllMissingDeviceEntity();
List<MissingDeviceEntity> MDEs = new ArrayList<>();
if (!MMEs.isEmpty()) {
missingDeviceDao.deleteAll();
for (MMEntity MME : MMEs) {
MissingDeviceEntity MDE = new MissingDeviceEntity();
MDE.setColumns(MME.getColumns());
MDE.setTime(MME.getTime());
MDEs.add(MDE);
}
missingDeviceDao.saveAll(MDEs);
}
this.endLog(methodName,MDEs);
return MDEs;
} catch (final Exception e) {
logger.error(e.getMessage());
this.errorLog(methodName,e);
throw e;
}
}
但是如果我尝试在某个时间点停止应用程序,特别是在进行 REST 调用之前,则会引发以下异常:
Caused by: java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@27494e46 has been closed already
我声明,如果我通过 swagger 手动执行 REST 调用并因此没有 @Scheduled 注释,则不会抛出此异常。
我该如何着手解决问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)