Task scheduling using cron expression from properties file

前端 未结 4 1461
栀梦
栀梦 2021-01-01 15:32

I have written a cron job:

@Scheduled(cron=\"${process.virtual.account.start}\")
public void ecomProcessVirAccOrderPaymentsScheduler() {
    LOGGER.info(\"St         


        
4条回答
  •  感动是毒
    2021-01-01 16:21

    Which version of spring framework are you using? This won't work if it is less than 3.0.1.

    Bug Report here in Spring 3.0.0 and it has been fixed in 3.0.1.

    So if you are using Spring 3.0.1 or greater then following things you have to do to use in cron expression

  • Make an entry in applicationContext.xml for PropertyPlaceHolderConfigurer class that is
    
        
            
                classpath:ApplicationProps.properties
            
        
    
    
    After That Use it in using the @Scheduled method like

    Update: In case if you are using spring boot no need to do anything, below code excerpt should work.

    @Scheduled(cron="${instructionSchedularTime}")
    public void load(){
    }
    

    Note: fixed delay and fixed-rate cann't take property value from placeholder because they take long value. Cron attribute take argument as String so you can use placeholder for that.

提交回复
热议问题