Spring Boot 定时任务的使用

@Configuration
@EnableScheduling
public class ScheduleConfig {

    private final Logger logger = LoggerFactory.getLogger(ScheduleConfig.class);

    @Autowired
    private SBUXPingService sbuxPingService;

    @Scheduled(cron = "0/10 * * * * ?") // 每10秒执行一次
    public void scheduler() {
        if (sbuxPingService.schedulePing()) {
            logger.error("============== 定时Ping成功 ===============");
        } else {
            logger.error("============== 定时Ping失败 ===============");
        }
    }

}

 

posted on 2017-06-12 09:53  沐雨橙风丶  阅读(519)  评论(0编辑  收藏  举报