定時任務,執行時間動態配置方式


 

如果配置內容不在application.yml或application.properties,則需要在類上注解

@PropertySource(value = "classpath:task.properties",encoding = "UTF-8")


具體執行的方法上寫這個
@Scheduled(cron="${Task_expireOTCAdsState_cron}") 


import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Component
@PropertySource(value = "classpath:task.properties",encoding = "UTF-8")
public class QuartzService {
    
    @Autowired
    private OTCAdsService otcAdsService;
    
    
    /**
     * 定時任務更新廣告過期
     */
    @Scheduled(cron="${Task_expireOTCAdsState_cron}") 
//    @Scheduled(cron = "0 0/1 * * * ?")
    public void expireOTCAdsState(){
        LogUtils.info(this.getClass(), "廣告過期執行開始:");
        
        LogUtils.info(this.getClass(), "廣告過期執行行數:" + count);
        LogUtils.info(this.getClass(), "廣告過期執行結束:");
    }

}

 

 

task.properties

# 任務執行時間cron配置
Task_expireOTCAdsState_cron=0 0/1 * * * ?

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM