Springboot中的定时任务初初初初级

最近刚刚接触Sringboot中的定时任务写了一个最最最初阶版的定时任务,作如下记录:


首先在启动类中添加注解

@EnableScheduling

然后就可以直接通过注解@Scheduled编写我们的定时任务了

@Service
public class TimeService
{


    @Scheduled(cron = "0 0/1 * * * ?")
    public void timmerToNow()
    {
        System.out.println("lalala");
    }
}

其中,corn值代表每分钟执行一次,@Scheduled注解还有其他几个参数,这里没有用到暂不做说明了,自己看方法介绍也很好理解

执行情况如下,,每分钟一次:


over

猜你喜欢

转载自blog.csdn.net/qq_38431305/article/details/80909265