Spring Boot 调度器

Spring Boot 可以很简单的添加一个调度任务

首先需要添加maven依赖

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>

然后对需要定时调度的任务添加注解

    @Scheduled(cron = "*/2 * * * * ?")
    public void scheduledMethod() {
        // 设置为两秒启动一次
    }

最后需要开启一下注解

@SpringBootApplication
@EnableScheduling
public class WebApplication {

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

}

但是并不支持动态配置

不过可以满足日常的一些需要了

原文地址:https://www.cnblogs.com/stdpain/p/11776892.html