The spring-boot-starter-quartz dependency adds the Quartz Scheduler to a Spring Boot application and wires it up automatically. It pulls in Quartz and the Spring scheduling support, then auto-configures a Scheduler bean, a job factory that can inject Spring beans into jobs, and optional JDBC-backed persistence. You declare JobDetail and Trigger beans, and Boot registers them with the scheduler at startup.
Use Quartz when @Scheduled is not enough: persistent jobs that survive restarts, clustered execution so only one node runs a job, and job data that can be changed at runtime.
@ScheduledThe starter is a convenience dependency. Adding it gives you the Quartz library, spring-context-support (which contains the Spring integration classes such as SchedulerFactoryBean and QuartzJobBean) and spring-tx. You do not choose or align Quartz versions yourself, because the Spring Boot dependency management already pins a tested version.
For Gradle, use implementation 'org.springframework.boot:spring-boot-starter-quartz'. Without the starter you would add Quartz, declare a SchedulerFactoryBean, configure a job factory and handle the lifecycle manually.
When Quartz is on the classpath, QuartzAutoConfiguration creates the following:
SchedulerFactoryBean that builds and manages the Scheduler and starts it with the application context.@Autowired fields and constructor injection work in your jobs.JobDetail, Trigger and Calendar bean found in the context.The scheduler is shut down with the application context. Set spring.quartz.wait-for-jobs-to-complete-on-shutdown=true if running jobs should be allowed to finish first.
A job is a class that implements org.quartz.Job or, more conveniently, extends QuartzJobBean. Jobs are created by Quartz for each execution, so keep them stateless and put data in the JobDataMap.
Then declare the job detail and trigger as beans:
This runs the job every day at 02:00. Quartz cron expressions have a seconds field and use ? for "no specific value" in either the day-of-month or day-of-week field, which differs slightly from Spring's own @Scheduled(cron = ...) syntax.
You can also inject the Scheduler bean and schedule jobs at runtime, for example from a REST controller, using scheduler.scheduleJob(jobDetail, trigger).
By default jobs live in memory and are lost on restart. To persist them, point Quartz at a database:
initialize-schema accepts embedded (the default, only for embedded databases), always and never. In production prefer never and manage the QRTZ_* tables with Flyway or Liquibase. Quartz uses the application DataSource; to give it its own, annotate a DataSource bean with @QuartzDataSource. With isClustered enabled, several application instances share one schedule and each trigger fires on only one node.
@Scheduled| Need | @Scheduled | Quartz starter |
|---|---|---|
| Simple fixed-rate or cron task | Yes, minimal setup | Works, more code |
| Survive restarts, misfire handling | No | Yes, with JDBC store |
| Cluster-safe single execution | No (needs extra locking) | Yes |
| Create or change jobs at runtime | No | Yes |
| Per-job data and calendars | No | Yes |
If you only need a periodic in-process task, @EnableScheduling with @Scheduled is simpler and has no extra dependency.
@Scheduled?No. They coexist. @Scheduled is for simple in-process tasks, while Quartz adds persistence, clustering and runtime management.
Yes. Boot configures a job factory that autowires job instances, so constructor or field injection works in classes that extend QuartzJobBean.
You are using the default in-memory store. Set spring.quartz.job-store-type=jdbc and provide the Quartz tables.
Set spring.quartz.auto-startup=false and start the scheduler yourself when you are ready.
spring-boot-starter-quartz gives you Quartz with Spring Boot conventions: a managed Scheduler, Spring-aware jobs, automatic registration of JobDetail and Trigger beans, and configuration through spring.quartz.* properties. Choose it when you need persistent, clustered or dynamically managed jobs, and stay with @Scheduled for simple periodic work.