0
# Configuration Properties
1
2
Spring Boot Batch Starter provides extensive configuration options through externalized properties under the `spring.batch` prefix, allowing fine-tuned control over batch processing behavior without code changes.
3
4
## Capabilities
5
6
### BatchProperties
7
8
Main configuration properties class that binds to `spring.batch` properties and provides structured access to batch configuration options.
9
10
```java { .api }
11
/**
12
* Configuration properties for Spring Batch under spring.batch prefix
13
*/
14
@ConfigurationProperties("spring.batch")
15
public class BatchProperties {
16
17
/**
18
* Gets job-related configuration properties
19
*/
20
public Job getJob();
21
22
/**
23
* Gets JDBC-related configuration properties
24
*/
25
public Jdbc getJdbc();
26
}
27
```
28
29
**Usage Examples:**
30
31
```java
32
@Component
33
public class BatchConfigurationService {
34
35
@Autowired
36
private BatchProperties batchProperties;
37
38
public void logConfiguration() {
39
String jobName = batchProperties.getJob().getName();
40
String tablePrefix = batchProperties.getJdbc().getTablePrefix();
41
System.out.println("Job: " + jobName + ", Tables: " + tablePrefix);
42
}
43
}
44
```
45
46
### Job Configuration Properties
47
48
Controls job execution behavior and startup parameters.
49
50
```java { .api }
51
/**
52
* Job-related configuration properties under spring.batch.job prefix
53
*/
54
public static class Job {
55
56
/**
57
* Job name to execute on startup. Must be specified if multiple Jobs are found in the context.
58
* Default: empty string (runs any single job found, fails if multiple jobs exist)
59
*/
60
public String getName();
61
62
/**
63
* Sets the specific job name to execute on application startup
64
*/
65
public void setName(String name);
66
}
67
```
68
69
**Property Configuration:**
70
71
```properties
72
# Specify which job to run on startup (required if multiple jobs exist)
73
spring.batch.job.name=dailyReportJob
74
75
# Disable automatic job execution on startup
76
spring.batch.job.enabled=false
77
```
78
79
**Usage Examples:**
80
81
```java
82
@SpringBootApplication
83
public class MultiJobApplication {
84
85
@Bean
86
public Job dailyReportJob(JobRepository jobRepository, Step reportStep) {
87
return new JobBuilder("dailyReportJob", jobRepository)
88
.start(reportStep)
89
.build();
90
}
91
92
@Bean
93
public Job weeklyCleanupJob(JobRepository jobRepository, Step cleanupStep) {
94
return new JobBuilder("weeklyCleanupJob", jobRepository)
95
.start(cleanupStep)
96
.build();
97
}
98
}
99
100
# application.properties
101
spring.batch.job.name=dailyReportJob # Only this job will run on startup
102
```
103
104
### JDBC Configuration Properties
105
106
Controls database behavior, schema initialization, and transaction settings for batch metadata storage.
107
108
```java { .api }
109
/**
110
* JDBC-related configuration properties under spring.batch.jdbc prefix
111
*/
112
public static class Jdbc {
113
114
/**
115
* Default schema location with platform placeholder
116
*/
117
public static final String DEFAULT_SCHEMA_LOCATION =
118
"classpath:org/springframework/batch/core/schema-@@platform@@.sql";
119
120
/**
121
* Whether to validate the transaction state before job execution
122
* Default: true
123
*/
124
public boolean isValidateTransactionState();
125
public void setValidateTransactionState(boolean validateTransactionState);
126
127
/**
128
* Transaction isolation level to use when creating job meta-data for new jobs
129
* Default: null (uses database default)
130
*/
131
public Isolation getIsolationLevelForCreate();
132
public void setIsolationLevelForCreate(Isolation isolationLevelForCreate);
133
134
/**
135
* Path to the SQL file to use to initialize the database schema
136
* Default: "classpath:org/springframework/batch/core/schema-@@platform@@.sql"
137
*/
138
public String getSchema();
139
public void setSchema(String schema);
140
141
/**
142
* Platform to use in initialization scripts if the @@platform@@ placeholder is used
143
* Auto-detected by default based on DataSource
144
*/
145
public String getPlatform();
146
public void setPlatform(String platform);
147
148
/**
149
* Table prefix for all the batch meta-data tables
150
* Default: null (uses Spring Batch default prefix)
151
*/
152
public String getTablePrefix();
153
public void setTablePrefix(String tablePrefix);
154
155
/**
156
* Database schema initialization mode
157
* Default: EMBEDDED (initialize only for embedded databases)
158
*/
159
public DatabaseInitializationMode getInitializeSchema();
160
public void setInitializeSchema(DatabaseInitializationMode initializeSchema);
161
}
162
```
163
164
**Property Configuration:**
165
166
```properties
167
# Database schema initialization
168
spring.batch.jdbc.initialize-schema=always
169
spring.batch.jdbc.platform=postgresql
170
spring.batch.jdbc.schema=classpath:custom-batch-schema.sql
171
172
# Table customization
173
spring.batch.jdbc.table-prefix=CUSTOM_BATCH_
174
175
# Transaction settings
176
spring.batch.jdbc.validate-transaction-state=true
177
spring.batch.jdbc.isolation-level-for-create=read_committed
178
```
179
180
**Usage Examples:**
181
182
```java
183
// Custom database configuration
184
@Configuration
185
public class BatchDatabaseConfiguration {
186
187
@Bean
188
@BatchDataSource
189
@ConfigurationProperties("batch.datasource")
190
public DataSource batchDataSource() {
191
return DataSourceBuilder.create().build();
192
}
193
}
194
195
# application.yml
196
batch:
197
datasource:
198
url: jdbc:postgresql://localhost:5432/batch_db
199
username: batch_user
200
password: batch_pass
201
202
spring:
203
batch:
204
jdbc:
205
initialize-schema: always
206
table-prefix: CUSTOM_BATCH_
207
platform: postgresql
208
```
209
210
## Database Schema Initialization Modes
211
212
Control when and how batch metadata tables are created:
213
214
```java { .api }
215
/**
216
* Database initialization modes for batch schema creation
217
*/
218
public enum DatabaseInitializationMode {
219
/**
220
* Never initialize the database schema
221
*/
222
NEVER,
223
224
/**
225
* Initialize only embedded databases (H2, HSQL, Derby)
226
*/
227
EMBEDDED,
228
229
/**
230
* Always initialize the database schema on startup
231
*/
232
ALWAYS
233
}
234
```
235
236
## Transaction Isolation Levels
237
238
Configure transaction isolation for job metadata operations:
239
240
```java { .api }
241
/**
242
* Transaction isolation levels for batch operations
243
*/
244
public enum Isolation {
245
DEFAULT, // Use database default
246
READ_UNCOMMITTED, // Lowest isolation, highest performance
247
READ_COMMITTED, // Most common isolation level
248
REPEATABLE_READ, // Prevents non-repeatable reads
249
SERIALIZABLE // Highest isolation, lowest performance
250
}
251
```
252
253
## Property Reference
254
255
### Complete Property List
256
257
```properties
258
# Job execution properties
259
spring.batch.job.enabled=true # Enable automatic job execution
260
spring.batch.job.name= # Specific job name to execute
261
262
# JDBC configuration properties
263
spring.batch.jdbc.initialize-schema=embedded # Schema initialization mode
264
spring.batch.jdbc.schema=classpath:org/springframework/batch/core/schema-@@platform@@.sql
265
spring.batch.jdbc.platform= # Database platform (auto-detected)
266
spring.batch.jdbc.table-prefix= # Custom table prefix
267
spring.batch.jdbc.validate-transaction-state=true # Enable transaction validation
268
spring.batch.jdbc.isolation-level-for-create=default # Transaction isolation level
269
```
270
271
### Environment-Specific Configuration
272
273
```yaml
274
# application-dev.yml
275
spring:
276
batch:
277
jdbc:
278
initialize-schema: always
279
table-prefix: DEV_BATCH_
280
job:
281
enabled: true
282
283
---
284
# application-prod.yml
285
spring:
286
batch:
287
jdbc:
288
initialize-schema: never # Schema managed externally in production
289
table-prefix: PROD_BATCH_
290
validate-transaction-state: true
291
isolation-level-for-create: read_committed
292
job:
293
enabled: false # Jobs triggered externally in production
294
```
295
296
## Integration with Other Properties
297
298
Batch properties work alongside other Spring Boot configuration:
299
300
```properties
301
# Database connection (works with batch DataSource)
302
spring.datasource.url=jdbc:h2:mem:batchdb
303
spring.datasource.driver-class-name=org.h2.Driver
304
305
# JPA settings (batch uses separate tables)
306
spring.jpa.hibernate.ddl-auto=create-drop
307
spring.jpa.show-sql=true
308
309
# Actuator endpoints for monitoring
310
management.endpoints.web.exposure.include=health,info,metrics
311
management.endpoint.health.show-details=always
312
```