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.
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.
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.
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=* * * ? * *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With