介绍
定时任务用于定时去执行某项操作,如:跑批数据,报表等。
一、配置文件
采用读取配置文件方式经行时间配置
application.properties
corn=*/1 * * * * *
二、代码
启动类
package com.guo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling 开启定时任务,自动扫描
public class SpringbootScheduleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootScheduleApplication.class, args);
}
}
定时任务类
package com.guo.task;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class Task {
@Scheduled(cron = "${corn}")
public void task(){
System.