Search code examples
javaspringspring-bootquartz-schedulerspring-boot-starter

How do I setup a Cron Quartz Trigger on Startup


I am setting up a few CronTriggers to kickoff a few different batch jobs at different times.

I have tried to search online, but can only find answers on how to schedule after say a web call or inside a different service class. I want theses triggers to be scheduled on startup.

How can I do that?

I have already built the Triggers and the JobDetails via their respective builders.

I am using Spring-boot-starter-quartz


Solution

  • I believe what you are looking for is to create a class that implements ApplicationRunner or CommandLineRunner. On startup of a spring application, spring will execute run command in this class and you can programmatically call your task on startup.

    See this if you want more info:

    https://www.concretepage.com/spring-boot/spring-boot-commandlinerunner-and-applicationrunner-example