0
点赞
收藏
分享

微信扫一扫

springBoot后端代码中使用定时器@Scheduled注解

拾光的Shelly 2022-02-18 阅读 111

第一步,在启动类中添加@EnableScheduling(必须)

/**
 * 启动程序
 * 
 */
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@EnableScheduling
public class RuoYiApplication
{
    public static void main(String[] args)
    {
       
    }
}

第二部,在要执行定时器的方法上添加@Scheduled(七子表达式)

    @Scheduled(cron="0/1 * * * * ? ")
    @GetMapping("/list")
    public void test01() throws Exception{

//        batchPaymentService.t();

//        batchPaymentService.doTaskOne();
//        batchPaymentService.doTaskTwo();
//        batchPaymentService.doTaskThree();
        System.out.println("执行完了");

    }

//执行结果,每一秒执行一次

举报

相关推荐

0 条评论