I have a @Scheduled
task in my application which is setup using CRON
and run every 4 hours. The problem I face is that the CRON
job does not start immediately after application startup but it starts only 4 hours after the application startup.
I tried to use a @PostConstruct
method inside the task to invoke it, but that results in an error due to an uninitialized Spring context.
Please tell me how I can make the Scheduled task run immediately on application deployment and then on every 4 hours after the deployment.
EDIT:
I would not use a @PostConstruct
since my scheduled method depends on other Beans , which are not initialized when this PostConstruct method runs for some reason.