Spring Boot中配置定时任务极其简单......
import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import java.text.SimpleDateFormat; import java.util.Date; /** * Created by winner_0715 on 2017/4/18. */ @Configuration @EnableScheduling public class SchedulingConfig { // 每5秒执行一次 @Scheduled(cron = "0/5 * * * * ?") public void scheduler() { System.out.println("SchedulingConfig.scheduler()" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); } }
一步搞定,也不需要配置其他的什么东西....不得不说,啧啧....
时间: 2024-11-01 15:33:57