我写了一份cron作业:
@Scheduled(cron = $ {process.virtual.account.start} )公共无效的ecomProcessVirAccOrderPaymentsScheduler(){ LOGGER.info(开始---> + this.getClass()。getCanonicalName()+ .ecomProcessVirAccOrderPaymentsScheduler()方法); schedulerJobHelper.ecomProcessVirAccOrderPaymentsScheduler(); LOGGER.info( End ---> + this.getClass()。getCanonicalName()+ .ecomProcessVirAccOrderPaymentsScheduler()方法); }我想将cron属性与 @一起使用已计划的批注将从外部属性文件填充。目前,我正在从应用程序范围内的属性文件中获取它。 我可以获取该值,但不能与 @Schedule 批注一起使用。
解决方案您正在使用哪个版本的spring框架?如果小于3.0.1,则无法使用。
在3.0.0春季发布的错误报告,并已在3.0.1版中进行了修复。您必须在cron表达式中使用
之后在@Scheduled方法中使用它,例如
更新:如果您使用的是 spring boot ,则无需执行任何操作,下面的代码摘录应该可以使用。
@Scheduled(cron = $ {instructionSchedularTime}) public void load(){}
注意:固定延迟和固定利率无法从占位符获取财产价值,因为它们需要长期价值。 Cron属性将参数设为String,因此您可以使用占位符。
I have written a cron job:
@Scheduled(cron="${process.virtual.account.start}") public void ecomProcessVirAccOrderPaymentsScheduler() { LOGGER.info("Start --->" + this.getClass().getCanonicalName() + ".ecomProcessVirAccOrderPaymentsScheduler() Method"); schedulerJobHelper.ecomProcessVirAccOrderPaymentsScheduler(); LOGGER.info("End --->" + this.getClass().getCanonicalName() + ".ecomProcessVirAccOrderPaymentsScheduler() Method"); }I want to get the cron attribute used with @Scheduled annotation to be populated from a external properties file. Currently I am fetching it from a property file inside the application scope. I am able to fetch the value, but not able to use it with @Schedule annotation.
解决方案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
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.
更多推荐
使用属性文件中的cron表达式进行任务调度
发布评论