如何使用Spring Boot修复有问题的计划任务

marziye:

我的计划任务是如下但是,当我使用的应用程序没有响应,@Scheduled(cron="0 46 17 * * *")而当我用@Scheduled(fixedRate = 50000),当保存在MongoDB的信息,该方案提供了一个错误

[ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.

: An unexpected error occurred during scheduled work. java.lang.NullPointerException

请帮我修理鳕鱼。


    @Scheduled(cron="0 46 17  * * *")
//  @Scheduled(fixedRate = 5000)
    @RequestMapping("/closeAttendance}")
    public void cloceAttendance() {
        System.out.println("-1");
        AttendanceService attendanceService=new AttendanceService();
        Date date=attendanceService.getCurrentDate();
        System.out.println("1");
        List<Attendance> attendances=arepo.findByDate(date);
if(attendances!=null) {
        System.out.println("attendances"+attendances.size());
        System.out.println("2");
//  
        for(Attendance attendance:attendances) {
            System.out.println("3");
            attendance=attendanceService.closeAttendance(attendance);
            System.out.println("4");
            System.out.println("attendance"+attendance.getDate()+" "+ attendance.getPerson());
//          arepo.save(attendance);

        }   

    }
}
恼怒的:

您的代码中没有错,仅缺少的是

@EnableScheduling

在类级别使用此注释,您的代码可以正常工作,如果适合您,也不要忘记投票。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章