Spring Boot 计划任务(定时任务)

本文介绍如何使用SpringBoot实现定时任务功能。通过@EnableScheduling注解启用定时任务支持,并展示了一个具体的任务类示例,该类每小时执行一次特定操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Boot使用标签来实现计划任务(定时任务)

  • @EnableScheduling
  • @Component
  • @Qualifier
  • @Primary
  • @Scheduled
标签具体含义自行百度

FashionGoApplication类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class FashionGoApplication {

    public static void main(String[] args) {
        SpringApplication.run(FashionGoApplication.class, args);
    }
}

任务类

@Component
@Qualifier
@Primary
public class Run {
    @Scheduled(fixedRate = 3600000)
    public void judgeItemOrder() {
        System.out.println("每隔1小时执行一次,3600000 = 60 * 60 * 1000");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值