Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task scheduling using cron expression from properties file

Tags:

cron

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.

like image 362
Sam Avatar asked Jun 19 '14 11:06

Sam


People also ask

What does 0 * * * * mean in crontab?

0 * * * * -this means the cron will run always when the minutes are 0 (so hourly) 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.

How do I schedule a cron job in spring boot?

Java Cron ExpressionThe @EnableScheduling annotation is used to enable the scheduler for your application. This annotation should be added into the main Spring Boot application class file. The @Scheduled annotation is used to trigger the scheduler for a specific time period.


1 Answers

it is working in spring boot.

@Scheduled(cron="${cronExpression}") private void testSchedule()  {     System.out.println("Helloooo"); } 

in application.properties I have a property like this as below:

cronExpression=* * * ? * * 
like image 155
karthik akinapelli Avatar answered Sep 19 '22 18:09

karthik akinapelli