Starter for using the Quartz scheduler in Spring Boot applications with auto-configuration support
npx @tessl/cli install tessl/maven-org-springframework-boot--spring-boot-starter-quartz@3.5.00
# Spring Boot Starter Quartz
1
2
Spring Boot Starter Quartz provides auto-configuration for the Quartz Scheduler framework, enabling seamless job scheduling capabilities in Spring Boot applications. It automatically configures Scheduler instances, supports both in-memory and JDBC-based job stores, and provides monitoring through Spring Boot Actuator endpoints.
3
4
## Package Information
5
6
- **Package Name**: org.springframework.boot:spring-boot-starter-quartz
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: Add to your `pom.xml`:
10
11
```xml
12
<dependency>
13
<groupId>org.springframework.boot</groupId>
14
<artifactId>spring-boot-starter-quartz</artifactId>
15
<version>3.5.3</version>
16
</dependency>
17
```
18
19
For Gradle:
20
21
```gradle
22
implementation 'org.springframework.boot:spring-boot-starter-quartz:3.5.3'
23
```
24
25
## Core Imports
26
27
```java
28
import org.springframework.boot.autoconfigure.quartz.*;
29
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
30
import org.quartz.*;
31
```
32
33
For actuator endpoints:
34
35
```java
36
import org.springframework.boot.actuate.quartz.*;
37
import org.springframework.boot.actuate.autoconfigure.quartz.*;
38
```
39
40
For customization:
41
42
```java
43
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;
44
import org.springframework.boot.autoconfigure.quartz.QuartzDataSource;
45
import org.springframework.boot.autoconfigure.quartz.QuartzTransactionManager;
46
```
47
48
## Basic Usage
49
50
The starter provides automatic configuration when added as a dependency. Basic job scheduling setup:
51
52
```java
53
import org.springframework.boot.SpringApplication;
54
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.context.annotation.Bean;
56
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
57
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;
58
import org.springframework.stereotype.Component;
59
import org.quartz.*;
60
61
@SpringBootApplication
62
public class QuartzApplication {
63
64
public static void main(String[] args) {
65
SpringApplication.run(QuartzApplication.class, args);
66
}
67
68
@Bean
69
public JobDetail sampleJobDetail() {
70
return JobBuilder.newJob(SampleJob.class)
71
.withIdentity("sampleJob")
72
.usingJobData("name", "Spring Boot Quartz")
73
.storeDurably()
74
.build();
75
}
76
77
@Bean
78
public Trigger sampleJobTrigger() {
79
return TriggerBuilder.newTrigger()
80
.forJob(sampleJobDetail())
81
.withIdentity("sampleTrigger")
82
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
83
.withIntervalInSeconds(10)
84
.repeatForever())
85
.build();
86
}
87
}
88
89
@Component
90
public class SampleJob implements Job {
91
@Override
92
public void execute(JobExecutionContext context) throws JobExecutionException {
93
System.out.println("Sample job executed: " +
94
context.getJobDetail().getJobDataMap().getString("name"));
95
}
96
}
97
```
98
99
Configuration via `application.properties`:
100
101
```properties
102
# Job store configuration
103
spring.quartz.job-store-type=memory
104
spring.quartz.scheduler-name=MyScheduler
105
spring.quartz.auto-startup=true
106
spring.quartz.startup-delay=5s
107
spring.quartz.wait-for-jobs-to-complete-on-shutdown=true
108
109
# JDBC configuration (when using JDBC job store)
110
spring.quartz.job-store-type=jdbc
111
spring.quartz.jdbc.initialize-schema=embedded
112
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
113
```
114
115
## Architecture
116
117
Spring Boot Starter Quartz integrates Quartz Scheduler with Spring Boot's auto-configuration mechanism:
118
119
- **Auto-configuration**: `QuartzAutoConfiguration` automatically configures `SchedulerFactoryBean` when Quartz is on the classpath
120
- **Properties Binding**: `QuartzProperties` provides type-safe configuration binding for `spring.quartz.*` properties
121
- **Job Store Support**: Automatic configuration for both in-memory (`MEMORY`) and database-backed (`JDBC`) job stores
122
- **Spring Integration**: Seamless integration with Spring's dependency injection, transaction management, and lifecycle management
123
- **Actuator Support**: Management endpoints for monitoring jobs, triggers, and scheduler status
124
- **Customization**: `SchedulerFactoryBeanCustomizer` interface for advanced scheduler configuration
125
126
## Capabilities
127
128
### Auto-configuration
129
130
Core auto-configuration classes that automatically set up Quartz Scheduler when the starter is present. Handles scheduler factory bean creation, job store configuration, and Spring integration.
131
132
```java { .api }
133
@AutoConfiguration
134
public class QuartzAutoConfiguration {
135
@Bean
136
@ConditionalOnMissingBean
137
public SchedulerFactoryBean quartzScheduler(
138
QuartzProperties properties,
139
ObjectProvider<SchedulerFactoryBeanCustomizer> customizers,
140
ObjectProvider<JobDetail> jobDetails,
141
Map<String, Calendar> calendars,
142
ObjectProvider<Trigger> triggers,
143
ApplicationContext applicationContext
144
);
145
}
146
```
147
148
[Auto-configuration](./auto-configuration.md)
149
150
### Configuration Properties
151
152
Type-safe configuration properties for customizing Quartz behavior through `application.properties` or `application.yml`. Covers scheduler settings, job store configuration, and JDBC initialization.
153
154
```java { .api }
155
@ConfigurationProperties("spring.quartz")
156
public class QuartzProperties {
157
public JobStoreType getJobStoreType();
158
public void setJobStoreType(JobStoreType jobStoreType);
159
public String getSchedulerName();
160
public boolean isAutoStartup();
161
public Duration getStartupDelay();
162
public boolean isWaitForJobsToCompleteOnShutdown();
163
public boolean isOverwriteExistingJobs();
164
public Map<String, String> getProperties();
165
public Jdbc getJdbc();
166
}
167
168
public enum JobStoreType {
169
MEMORY, JDBC
170
}
171
```
172
173
[Configuration Properties](./configuration-properties.md)
174
175
### Scheduler Customization
176
177
Interfaces and annotations for customizing scheduler behavior, data sources, and transaction managers. Enables fine-grained control over Quartz configuration in Spring Boot applications.
178
179
```java { .api }
180
@FunctionalInterface
181
public interface SchedulerFactoryBeanCustomizer {
182
void customize(SchedulerFactoryBean schedulerFactoryBean);
183
}
184
185
@Qualifier
186
public @interface QuartzDataSource {
187
}
188
189
@Qualifier
190
public @interface QuartzTransactionManager {
191
}
192
```
193
194
[Scheduler Customization](./scheduler-customization.md)
195
196
### Actuator Integration
197
198
Management endpoints for monitoring and inspecting Quartz scheduler state, including jobs, triggers, and execution history. Provides both REST API and web interface for scheduler management.
199
200
```java { .api }
201
@Endpoint(id = "quartz")
202
public class QuartzEndpoint {
203
@ReadOperation
204
public QuartzDescriptor quartzReport() throws SchedulerException;
205
206
public QuartzGroupsDescriptor quartzJobGroups() throws SchedulerException;
207
public QuartzGroupsDescriptor quartzTriggerGroups() throws SchedulerException;
208
}
209
210
@AutoConfiguration
211
public class QuartzEndpointAutoConfiguration {
212
@Bean
213
public QuartzEndpoint quartzEndpoint(
214
Scheduler scheduler,
215
ObjectProvider<SanitizingFunction> sanitizingFunctions
216
);
217
}
218
```
219
220
[Actuator Integration](./actuator-integration.md)
221
222
## Types
223
224
```java { .api }
225
public class QuartzProperties.Jdbc {
226
public String getSchema();
227
public void setSchema(String schema);
228
public String getPlatform();
229
public void setPlatform(String platform);
230
public DatabaseInitializationMode getInitializeSchema();
231
public void setInitializeSchema(DatabaseInitializationMode initializeSchema);
232
public List<String> getCommentPrefix();
233
public void setCommentPrefix(List<String> commentPrefix);
234
}
235
236
public class QuartzDataSourceScriptDatabaseInitializer {
237
public QuartzDataSourceScriptDatabaseInitializer(
238
DataSource dataSource,
239
QuartzProperties properties
240
);
241
}
242
243
public class SchedulerDependsOnDatabaseInitializationDetector {
244
// Detects scheduler dependencies on database initialization
245
}
246
```