springboot cron定时器
Posted 苏格拉的底
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot cron定时器相关的知识,希望对你有一定的参考价值。
定时任务一个类
package com.example.main.cron;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
public class CronTask
// Every hour on the hour
@Scheduled(cron = "*/5 * * * * ?")
// 每隔5秒执行一次
public void fiveSecond()
System.out.println("每隔5秒执行一次打印");
以上是关于springboot cron定时器的主要内容,如果未能解决你的问题,请参考以下文章