spring boot启动定时任务

spring boot启动定时任务,第1张

spring boot启动定时任务

1.主程序入口类上加入注解
@EnableScheduling //开启基于注解的定时任务

2.新建测试类

package com.example.demo.service.impl;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class TestShedualServiceImpl {

    @Scheduled(cron = "0/5 * * * * ? ")
    public void TestSchedul(){
        System.out.println("5秒运行一次");
    }
}

3.启动观察结果

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5695246.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存