Skip to content

Commit 4717e7c

Browse files
committed
Migrate to Spring Batch infrastructure package
This commit refactors the codebase to use the new Spring Batch infrastructure package structure, moving from org.springframework.batch.item to org.springframework.batch.infrastructure.item across all modules. The migration was necessary following the Spring Batch 7.x release, which reorganized the API. Key changes include: - Update all ItemReader, ItemWriter, and ItemProcessor imports to use the new infrastructure package location - Migrate file processing components (FlatFileItemReader/Writer, LineMapper, LineTokenizer, etc.) to infrastructure.item.file - Update database components (JdbcBatchItemWriter, JdbcCursorItemReader) to infrastructure.item.database - Migrate messaging components (KafkaItemReader/Writer, AmqpItemReader/Writer) to infrastructure.item package Additional changes: - Fix test compatibility by changing jobExecution.getJobId() to jobExecution.getId() following API updates - Add spring-boot-starter-jdbc dependency to support JDBC operations - Correct testcontainers dependency artifact ID from rabbitmq to testcontainers-rabbitmq - Fix FlatFileItemReaderAutoConfiguration logic to conditionally set lineTokenizer only when lineMapper is not present - Simplify JobParametersEvent class by removing redundant code and streamlining event handling - incrementExistingExecution not valid test after batch release
1 parent 9daf9e5 commit 4717e7c

File tree

74 files changed

+370
-508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+370
-508
lines changed

spring-cloud-starter-single-step-batch-job/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
<artifactId>spring-boot-starter-test</artifactId>
4848
<scope>test</scope>
4949
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-jdbc</artifactId>
53+
</dependency>
5054
<dependency>
5155
<groupId>org.springframework.batch</groupId>
5256
<artifactId>spring-batch-test</artifactId>
@@ -73,7 +77,7 @@
7377
</dependency>
7478
<dependency>
7579
<groupId>org.testcontainers</groupId>
76-
<artifactId>rabbitmq</artifactId>
80+
<artifactId>testcontainers-rabbitmq</artifactId>
7781
<scope>test</scope>
7882
</dependency>
7983
<dependency>

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/RangeConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
package org.springframework.cloud.task.batch.autoconfigure;
1818

19-
import org.springframework.batch.item.file.transform.Range;
19+
import org.springframework.batch.infrastructure.item.file.transform.Range;
2020
import org.springframework.core.convert.converter.Converter;
2121

2222
/**
2323
* Converter for taking properties of format {@code start-end} or {@code start} (where
2424
* start and end are both integers) and converting them into {@link Range} instances for
25-
* configuring a {@link org.springframework.batch.item.file.FlatFileItemReader}.
25+
* configuring a
26+
* {@link org.springframework.batch.infrastructure.item.file.FlatFileItemReader}.
2627
*
2728
* @author Michael Minella
2829
* @since 2.3

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.springframework.batch.core.step.Step;
2525
import org.springframework.batch.core.step.builder.SimpleStepBuilder;
2626
import org.springframework.batch.core.step.builder.StepBuilder;
27-
import org.springframework.batch.item.ItemProcessor;
28-
import org.springframework.batch.item.ItemReader;
29-
import org.springframework.batch.item.ItemWriter;
27+
import org.springframework.batch.infrastructure.item.ItemProcessor;
28+
import org.springframework.batch.infrastructure.item.ItemReader;
29+
import org.springframework.batch.infrastructure.item.ItemWriter;
3030
import org.springframework.beans.factory.annotation.Autowired;
3131
import org.springframework.boot.autoconfigure.AutoConfiguration;
3232
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemReaderAutoConfiguration.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import org.springframework.batch.item.file.FlatFileItemReader;
25-
import org.springframework.batch.item.file.LineCallbackHandler;
26-
import org.springframework.batch.item.file.LineMapper;
27-
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
28-
import org.springframework.batch.item.file.mapping.FieldSetMapper;
29-
import org.springframework.batch.item.file.separator.RecordSeparatorPolicy;
30-
import org.springframework.batch.item.file.transform.FieldSet;
31-
import org.springframework.batch.item.file.transform.LineTokenizer;
32-
import org.springframework.batch.item.file.transform.Range;
24+
import org.apache.commons.logging.Log;
25+
import org.apache.commons.logging.LogFactory;
26+
27+
import org.springframework.batch.infrastructure.item.file.FlatFileItemReader;
28+
import org.springframework.batch.infrastructure.item.file.LineCallbackHandler;
29+
import org.springframework.batch.infrastructure.item.file.LineMapper;
30+
import org.springframework.batch.infrastructure.item.file.builder.FlatFileItemReaderBuilder;
31+
import org.springframework.batch.infrastructure.item.file.mapping.FieldSetMapper;
32+
import org.springframework.batch.infrastructure.item.file.separator.RecordSeparatorPolicy;
33+
import org.springframework.batch.infrastructure.item.file.transform.FieldSet;
34+
import org.springframework.batch.infrastructure.item.file.transform.LineTokenizer;
35+
import org.springframework.batch.infrastructure.item.file.transform.Range;
3336
import org.springframework.beans.factory.annotation.Autowired;
3437
import org.springframework.boot.autoconfigure.AutoConfiguration;
3538
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -52,6 +55,8 @@
5255
@AutoConfigureAfter(BatchAutoConfiguration.class)
5356
public class FlatFileItemReaderAutoConfiguration {
5457

58+
private static final Log logger = LogFactory.getLog(FlatFileItemReaderAutoConfiguration.class);
59+
5560
private final FlatFileItemReaderProperties properties;
5661

5762
public FlatFileItemReaderAutoConfiguration(FlatFileItemReaderProperties properties) {
@@ -77,7 +82,6 @@ public FlatFileItemReader<Map<String, Object>> itemReader(@Autowired(required =
7782
.linesToSkip(this.properties.getLinesToSkip())
7883
.comments(this.properties.getComments().toArray(new String[this.properties.getComments().size()]));
7984

80-
mapFlatFileItemReaderBuilder.lineTokenizer(lineTokenizer);
8185
if (recordSeparatorPolicy != null) {
8286
mapFlatFileItemReaderBuilder.recordSeparatorPolicy(recordSeparatorPolicy);
8387
}
@@ -104,6 +108,15 @@ else if (this.properties.isFixedLength()) {
104108
.fieldSetMapper(new MapFieldSetMapper())
105109
.beanMapperStrict(this.properties.isParsingStrict());
106110
}
111+
else {
112+
mapFlatFileItemReaderBuilder.lineTokenizer(lineTokenizer);
113+
}
114+
115+
if (lineTokenizer != null && (this.properties.isDelimited() || this.properties.isFixedLength())) {
116+
logger.warn("Custom LineTokenizer bean provided but will be ignored because "
117+
+ "delimited or fixed-length properties are configured. "
118+
+ "Remove the custom bean or clear delimited/fixedLength properties.");
119+
}
107120

108121
return mapFlatFileItemReaderBuilder.build();
109122
}
@@ -116,7 +129,9 @@ public static class MapFieldSetMapper implements FieldSetMapper<Map<String, Obje
116129

117130
@Override
118131
public Map<String, Object> mapFieldSet(FieldSet fieldSet) {
119-
return new HashMap<String, Object>((Map) fieldSet.getProperties());
132+
Map<String, Object> map = new HashMap<>();
133+
fieldSet.getProperties().forEach((key, value) -> map.put(key.toString(), value));
134+
return map;
120135
}
121136

122137
}

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemReaderProperties.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.springframework.batch.item.file.FlatFileItemReader;
23-
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
24-
import org.springframework.batch.item.file.transform.Range;
22+
import org.springframework.batch.infrastructure.item.file.FlatFileItemReader;
23+
import org.springframework.batch.infrastructure.item.file.transform.DelimitedLineTokenizer;
24+
import org.springframework.batch.infrastructure.item.file.transform.Range;
2525
import org.springframework.boot.context.properties.ConfigurationProperties;
2626
import org.springframework.core.io.Resource;
2727

@@ -41,7 +41,7 @@ public class FlatFileItemReaderProperties {
4141

4242
/**
4343
* The name used to calculate the key within the
44-
* {@link org.springframework.batch.item.ExecutionContext}. Required if
44+
* {@link org.springframework.batch.infrastructure.item.ExecutionContext}. Required if
4545
* {@link #setSaveState} is set to {@code true}.
4646
*/
4747
private String name;
@@ -105,8 +105,8 @@ public class FlatFileItemReaderProperties {
105105

106106
/**
107107
* Indicates that a
108-
* {@link org.springframework.batch.item.file.transform.FixedLengthTokenizer} should
109-
* be used to parse the records in the file.
108+
* {@link org.springframework.batch.infrastructure.item.file.transform.FixedLengthTokenizer}
109+
* should be used to parse the records in the file.
110110
*/
111111
private boolean fixedLength = false;
112112

@@ -135,8 +135,10 @@ public boolean isSaveState() {
135135

136136
/**
137137
* Configure if the state of the
138-
* {@link org.springframework.batch.item.ItemStreamSupport} should be persisted within
139-
* the {@link org.springframework.batch.item.ExecutionContext} for restart purposes.
138+
* {@link org.springframework.batch.infrastructure.item.ItemStreamSupport} should be
139+
* persisted within the
140+
* {@link org.springframework.batch.infrastructure.item.ExecutionContext} for restart
141+
* purposes.
140142
* @param saveState defaults to true
141143
*/
142144
public void setSaveState(boolean saveState) {
@@ -154,10 +156,10 @@ public String getName() {
154156

155157
/**
156158
* The name used to calculate the key within the
157-
* {@link org.springframework.batch.item.ExecutionContext}. Required if
159+
* {@link org.springframework.batch.infrastructure.item.ExecutionContext}. Required if
158160
* {@link #setSaveState} is set to true.
159161
* @param name name of the reader instance
160-
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
162+
* @see org.springframework.batch.infrastructure.item.ItemStreamSupport#setName(String)
161163
*/
162164
public void setName(String name) {
163165
this.name = name;
@@ -174,7 +176,7 @@ public int getMaxItemCount() {
174176
/**
175177
* Configure the max number of items to be read.
176178
* @param maxItemCount the max items to be read
177-
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
179+
* @see org.springframework.batch.infrastructure.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
178180
*/
179181
public void setMaxItemCount(int maxItemCount) {
180182
this.maxItemCount = maxItemCount;
@@ -191,7 +193,7 @@ public int getCurrentItemCount() {
191193
/**
192194
* Index for the current item. Also used on restarts to indicate where to start from.
193195
* @param currentItemCount current index
194-
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
196+
* @see org.springframework.batch.infrastructure.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
195197
*/
196198
public void setCurrentItemCount(int currentItemCount) {
197199
this.currentItemCount = currentItemCount;
@@ -361,8 +363,8 @@ public boolean isFixedLength() {
361363

362364
/**
363365
* Indicates that a
364-
* {@link org.springframework.batch.item.file.transform.FixedLengthTokenizer} should
365-
* be used to parse the records in the file.
366+
* {@link org.springframework.batch.infrastructure.item.file.transform.FixedLengthTokenizer}
367+
* should be used to parse the records in the file.
366368
* @param fixedLength true if the records should be tokenized by column index
367369
*/
368370
public void setFixedLength(boolean fixedLength) {

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemWriterAutoConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23-
import org.springframework.batch.item.file.FlatFileFooterCallback;
24-
import org.springframework.batch.item.file.FlatFileHeaderCallback;
25-
import org.springframework.batch.item.file.FlatFileItemWriter;
26-
import org.springframework.batch.item.file.builder.FlatFileItemWriterBuilder;
27-
import org.springframework.batch.item.file.transform.FieldExtractor;
28-
import org.springframework.batch.item.file.transform.LineAggregator;
23+
import org.springframework.batch.infrastructure.item.file.FlatFileFooterCallback;
24+
import org.springframework.batch.infrastructure.item.file.FlatFileHeaderCallback;
25+
import org.springframework.batch.infrastructure.item.file.FlatFileItemWriter;
26+
import org.springframework.batch.infrastructure.item.file.builder.FlatFileItemWriterBuilder;
27+
import org.springframework.batch.infrastructure.item.file.transform.FieldExtractor;
28+
import org.springframework.batch.infrastructure.item.file.transform.LineAggregator;
2929
import org.springframework.beans.factory.annotation.Autowired;
3030
import org.springframework.boot.autoconfigure.AutoConfiguration;
3131
import org.springframework.boot.autoconfigure.AutoConfigureAfter;

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemWriterProperties.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.util.Locale;
2020

21-
import org.springframework.batch.item.file.FlatFileItemWriter;
21+
import org.springframework.batch.infrastructure.item.file.FlatFileItemWriter;
2222
import org.springframework.boot.context.properties.ConfigurationProperties;
2323
import org.springframework.core.io.Resource;
2424

@@ -104,7 +104,7 @@ public class FlatFileItemWriterProperties {
104104

105105
/**
106106
* The name used to calculate the key within the
107-
* {@link org.springframework.batch.item.ExecutionContext}. Required if
107+
* {@link org.springframework.batch.infrastructure.item.ExecutionContext}. Required if
108108
* {@link #setSaveState} is set to {@code true}.
109109
*/
110110
private String name;
@@ -142,8 +142,10 @@ public boolean isSaveState() {
142142

143143
/**
144144
* Configure if the state of the
145-
* {@link org.springframework.batch.item.ItemStreamSupport} should be persisted within
146-
* the {@link org.springframework.batch.item.ExecutionContext} for restart purposes.
145+
* {@link org.springframework.batch.infrastructure.item.ItemStreamSupport} should be
146+
* persisted within the
147+
* {@link org.springframework.batch.infrastructure.item.ExecutionContext} for restart
148+
* purposes.
147149
* @param saveState defaults to true
148150
*/
149151
public void setSaveState(boolean saveState) {
@@ -161,10 +163,10 @@ public String getName() {
161163

162164
/**
163165
* The name used to calculate the key within the
164-
* {@link org.springframework.batch.item.ExecutionContext}. Required if
166+
* {@link org.springframework.batch.infrastructure.item.ExecutionContext}. Required if
165167
* {@link #setSaveState} is set to true.
166168
* @param name name of the reader instance
167-
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
169+
* @see org.springframework.batch.infrastructure.item.ItemStreamSupport#setName(String)
168170
*/
169171
public void setName(String name) {
170172
this.name = name;

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcBatchItemWriterAutoConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
2525

26-
import org.springframework.batch.item.database.ItemPreparedStatementSetter;
27-
import org.springframework.batch.item.database.ItemSqlParameterSourceProvider;
28-
import org.springframework.batch.item.database.JdbcBatchItemWriter;
29-
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;
26+
import org.springframework.batch.infrastructure.item.database.ItemPreparedStatementSetter;
27+
import org.springframework.batch.infrastructure.item.database.ItemSqlParameterSourceProvider;
28+
import org.springframework.batch.infrastructure.item.database.JdbcBatchItemWriter;
29+
import org.springframework.batch.infrastructure.item.database.builder.JdbcBatchItemWriterBuilder;
3030
import org.springframework.beans.factory.annotation.Autowired;
3131
import org.springframework.beans.factory.annotation.Qualifier;
3232
import org.springframework.boot.autoconfigure.AutoConfiguration;

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcCursorItemReaderAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
2828

29-
import org.springframework.batch.item.database.JdbcCursorItemReader;
30-
import org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder;
29+
import org.springframework.batch.infrastructure.item.database.JdbcCursorItemReader;
30+
import org.springframework.batch.infrastructure.item.database.builder.JdbcCursorItemReaderBuilder;
3131
import org.springframework.beans.factory.annotation.Autowired;
3232
import org.springframework.beans.factory.annotation.Qualifier;
3333
import org.springframework.boot.autoconfigure.AutoConfiguration;

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemReaderAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.util.Map;
2222
import java.util.Properties;
2323

24-
import org.springframework.batch.item.kafka.KafkaItemReader;
25-
import org.springframework.batch.item.kafka.builder.KafkaItemReaderBuilder;
24+
import org.springframework.batch.infrastructure.item.kafka.KafkaItemReader;
25+
import org.springframework.batch.infrastructure.item.kafka.builder.KafkaItemReaderBuilder;
2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.boot.autoconfigure.AutoConfiguration;
2828
import org.springframework.boot.autoconfigure.AutoConfigureAfter;

0 commit comments

Comments
 (0)