這篇文章給大家介紹如何在Spring Boot中使用定時(shí)任務(wù),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
package org.springboot.sample.config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; @Configuration @EnableScheduling // 啟用定時(shí)任務(wù) public class SchedulingConfig { private final Logger logger = LoggerFactory.getLogger(getClass()); @Scheduled(cron = "0/20 * * * * ?") // 每20秒執(zhí)行一次 public void scheduler() { logger.info(">>>>>>>>>>>>> scheduled ... "); } }springboot是什么
springboot一種全新的編程規(guī)范,其設(shè)計(jì)目的是用來簡(jiǎn)化新Spring應(yīng)用的初始搭建以及開發(fā)過程,SpringBoot也是一個(gè)服務(wù)于框架的框架,服務(wù)范圍是簡(jiǎn)化配置文件。
關(guān)于如何在Spring Boot中使用定時(shí)任務(wù)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。