Add timing tasks to the springboot project

Step 1: Configure cron expression in application.properties configuration file

gocom.dataPanel.cron="0 0 15 * * ?"

yml file configuration

gocom:    
  task:
    dataPanel:
      cron: "0 0 15 * * ?"

Step 2: Add annotation @Scheduled to the method of executing the task

@Scheduled(cron = "${gocom.task.dataPanel.cron}")
public void evaluateUserSegment() {
    String batch = DateUtil.dateToString(DateUtil.dayOperation(-1),"yyyyMM");
    dataPanelTask(batch);
}

Step 3: Start the project

This method will be executed at 15 o'clock every day

Note: online cron expression generator

https://cron.qqe2.com/

Guess you like

Origin blog.csdn.net/wangpei930228/article/details/110551982