Spring Boot starter that provides comprehensive batch processing capabilities for enterprise Java applications with auto-configuration, job management, and database integration.
npx @tessl/cli install tessl/maven-org-springframework-boot--spring-boot-starter-batch@3.5.00
# Spring Boot Batch Starter
1
2
Spring Boot Batch Starter provides comprehensive auto-configuration and infrastructure for Spring Batch applications. It automatically configures batch processing components including job repositories, job launchers, transaction management, and database schema initialization, enabling developers to quickly build robust batch processing applications.
3
4
## Package Information
5
6
- **Package Name**: spring-boot-starter-batch
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**:
10
```xml
11
<dependency>
12
<groupId>org.springframework.boot</groupId>
13
<artifactId>spring-boot-starter-batch</artifactId>
14
<version>3.5.3</version>
15
</dependency>
16
```
17
18
**Gradle:**
19
```groovy
20
implementation 'org.springframework.boot:spring-boot-starter-batch:3.5.3'
21
```
22
23
## Core Imports
24
25
```java
26
import org.springframework.batch.core.Job;
27
import org.springframework.batch.core.JobLauncher;
28
import org.springframework.batch.core.repository.JobRepository;
29
import org.springframework.boot.autoconfigure.batch.BatchProperties;
30
import org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner;
31
```
32
33
## Basic Usage
34
35
```java
36
import org.springframework.batch.core.Job;
37
import org.springframework.batch.core.Step;
38
import org.springframework.batch.core.job.builder.JobBuilder;
39
import org.springframework.batch.core.repository.JobRepository;
40
import org.springframework.batch.core.step.builder.StepBuilder;
41
import org.springframework.batch.core.step.tasklet.Tasklet;
42
import org.springframework.batch.repeat.RepeatStatus;
43
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
45
import org.springframework.context.annotation.Bean;
46
import org.springframework.transaction.PlatformTransactionManager;
47
48
@SpringBootApplication
49
public class BatchApplication {
50
51
public static void main(String[] args) {
52
SpringApplication.run(BatchApplication.class, args);
53
}
54
55
@Bean
56
public Job sampleJob(JobRepository jobRepository, Step sampleStep) {
57
return new JobBuilder("sampleJob", jobRepository)
58
.start(sampleStep)
59
.build();
60
}
61
62
@Bean
63
public Step sampleStep(JobRepository jobRepository,
64
PlatformTransactionManager transactionManager) {
65
return new StepBuilder("sampleStep", jobRepository)
66
.tasklet(sampleTasklet(), transactionManager)
67
.build();
68
}
69
70
@Bean
71
public Tasklet sampleTasklet() {
72
return (contribution, chunkContext) -> {
73
System.out.println("Hello from Spring Batch!");
74
return RepeatStatus.FINISHED;
75
};
76
}
77
}
78
```
79
80
## Architecture
81
82
Spring Boot Batch Starter is built around several key components:
83
84
- **Auto-Configuration**: `BatchAutoConfiguration` automatically configures batch infrastructure when Spring Batch is on the classpath
85
- **Job Execution**: `JobLauncherApplicationRunner` automatically launches batch jobs on application startup
86
- **Configuration Properties**: `BatchProperties` provides externalized configuration via `spring.batch.*` properties
87
- **Database Integration**: Automatic schema initialization and transaction management for batch metadata
88
- **Observability**: Integration with Spring Boot Actuator for monitoring and metrics
89
- **Customization Points**: Qualifier annotations and customizer interfaces for advanced configuration
90
91
## Capabilities
92
93
### Auto-Configuration
94
95
Automatic configuration of Spring Batch infrastructure including job repository, job launcher, and transaction management with sensible defaults.
96
97
```java { .api }
98
@AutoConfiguration
99
public class BatchAutoConfiguration {
100
101
@Bean
102
@ConditionalOnMissingBean
103
public JobLauncherApplicationRunner jobLauncherApplicationRunner(
104
JobLauncher jobLauncher,
105
JobExplorer jobExplorer,
106
JobRepository jobRepository,
107
BatchProperties properties);
108
109
@Bean
110
@ConditionalOnMissingBean(ExitCodeGenerator.class)
111
public JobExecutionExitCodeGenerator jobExecutionExitCodeGenerator();
112
}
113
```
114
115
[Auto-Configuration](./auto-configuration.md)
116
117
### Configuration Properties
118
119
Externalized configuration for batch processing behavior, database settings, and job execution parameters.
120
121
```java { .api }
122
@ConfigurationProperties("spring.batch")
123
public class BatchProperties {
124
125
public Job getJob();
126
public Jdbc getJdbc();
127
128
public static class Job {
129
public String getName();
130
public void setName(String name);
131
}
132
133
public static class Jdbc {
134
public boolean isValidateTransactionState();
135
public void setValidateTransactionState(boolean validateTransactionState);
136
public Isolation getIsolationLevelForCreate();
137
public String getTablePrefix();
138
public DatabaseInitializationMode getInitializeSchema();
139
}
140
}
141
```
142
143
[Configuration Properties](./configuration-properties.md)
144
145
### Job Execution Management
146
147
Automatic job launching capabilities with application startup integration and exit code generation.
148
149
```java { .api }
150
public class JobLauncherApplicationRunner implements ApplicationRunner, InitializingBean {
151
152
public void run(ApplicationArguments args) throws JobExecutionException;
153
public void setJobName(String jobName);
154
public void setJobParameters(JobParameters jobParameters);
155
public void setJobParametersConverter(JobParametersConverter converter);
156
}
157
158
public class JobExecutionExitCodeGenerator
159
implements ApplicationListener<JobExecutionEvent>, ExitCodeGenerator {
160
161
public void onApplicationEvent(JobExecutionEvent event);
162
public int getExitCode();
163
}
164
```
165
166
[Job Execution Management](./job-execution.md)
167
168
### Customization and Qualification
169
170
Qualifier annotations and customization interfaces for advanced configuration scenarios with multiple data sources or transaction managers.
171
172
```java { .api }
173
@Qualifier
174
public @interface BatchDataSource {
175
}
176
177
@Qualifier
178
public @interface BatchTransactionManager {
179
}
180
181
@Qualifier
182
public @interface BatchTaskExecutor {
183
}
184
185
@FunctionalInterface
186
public interface BatchConversionServiceCustomizer {
187
void customize(ConfigurableConversionService configurableConversionService);
188
}
189
```
190
191
[Customization and Qualification](./customization.md)
192
193
## Configuration
194
195
### Application Properties
196
197
Key configuration properties for customizing batch behavior:
198
199
```properties
200
# Job execution
201
spring.batch.job.enabled=true
202
spring.batch.job.name=myBatchJob
203
204
# Database configuration
205
spring.batch.jdbc.initialize-schema=embedded
206
spring.batch.jdbc.table-prefix=BATCH_
207
spring.batch.jdbc.validate-transaction-state=true
208
spring.batch.jdbc.isolation-level-for-create=default
209
```
210
211
### Multiple Data Sources
212
213
When using multiple data sources, qualify the batch-specific data source:
214
215
```java
216
@Bean
217
@BatchDataSource
218
@ConfigurationProperties("batch.datasource")
219
public DataSource batchDataSource() {
220
return DataSourceBuilder.create().build();
221
}
222
```
223
224
### Custom Job Parameters
225
226
Configure job parameters through application arguments or properties:
227
228
```bash
229
java -jar myapp.jar --job.parameter1=value1 --job.parameter2=value2
230
```
231
232
## Types
233
234
```java { .api }
235
public class JobExecutionEvent extends ApplicationEvent {
236
public JobExecutionEvent(JobExecution execution);
237
public JobExecution getJobExecution();
238
}
239
240
public class BatchDataSourceScriptDatabaseInitializer
241
extends DataSourceScriptDatabaseInitializer {
242
243
public BatchDataSourceScriptDatabaseInitializer(
244
DataSource dataSource,
245
BatchProperties.Jdbc properties);
246
247
public BatchDataSourceScriptDatabaseInitializer(
248
DataSource dataSource,
249
DatabaseInitializationSettings settings);
250
251
public static DatabaseInitializationSettings getSettings(
252
DataSource dataSource,
253
BatchProperties.Jdbc properties);
254
}
255
256
class JobRepositoryDependsOnDatabaseInitializationDetector
257
extends AbstractBeansOfTypeDependsOnDatabaseInitializationDetector {
258
259
@Override
260
protected Set<Class<?>> getDependsOnDatabaseInitializationBeanTypes();
261
}
262
```