spring boot 集成定时任务

spring boot 集成定时任务,第1张

版本说明
  • Spring Boot 版本:2.6.1
添加web依赖
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-webartifactId>
dependency>
在启动类上添加注解开启任务支持
@SpringBootApplication
@EnableScheduling
public class BootTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(BootTestApplication.class, args);
    }
}
执行任务
@Component
public class TestJob {

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

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

原文地址: https://outofmemory.cn/langs/733785.html

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

发表评论

登录后才能评论

评论列表(0条)

保存