定时任务,执行时间动态配置方式


 

如果配置内容不在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