0

In springboot, I have a cron expression which is taken from db. The problem is the db is deployed with application and cron expression is given as a seed data but when the application starts the scheduler is called before db is created and I get a null pointer. I tried using @PostConstruct but it dint work out. Any suggestions?

  • Can you be more specific with your problem, what do you mean by db is deployed with application for example. If your db is deployed by the same application logic, then shouldn't you have access to the cron expression you deploy on the same app? – gsan Aug 24 '21 at 13:39
  • Can you tell us how you deploy your app and db ? You can retry untill you get a non null value or you can start your app after some time of your db deployment. – Shawrup Aug 24 '21 at 15:39

1 Answers1

0

Your question is not clear. But if the error occurs on @PostConstruct, then you can do an eventListener to listen when the application is ready

@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady(){
 // Do your stuff
}
  • The db is deployed along by the same application, so the cron is not accessible at that point of time. With post construct the scheduled method is accessed immediately after app starts but by this time the db files have not been executed. So naturally the cron expression will be blank. – GokuSS4 Aug 25 '21 at 03:25
  • We deploy by building the application and deploying the docker image – GokuSS4 Aug 25 '21 at 03:26