Skip to content

Commit 707b1bf

Browse files
committed
Remove the requirement for a Resource to be set
This commit removes the requirement for a Resource to be configured at build time. This requirement prevented the use of this builder along with the MultiResourceItemWriter. Resolves BATCH-2720
1 parent 33f04a9 commit 707b1bf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilder.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,9 @@
2020
import java.util.List;
2121
import java.util.Locale;
2222

23+
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
25+
2326
import org.springframework.batch.item.file.FlatFileFooterCallback;
2427
import org.springframework.batch.item.file.FlatFileHeaderCallback;
2528
import org.springframework.batch.item.file.FlatFileItemWriter;
@@ -44,6 +47,8 @@
4447
*/
4548
public class FlatFileItemWriterBuilder<T> {
4649

50+
protected Log logger = LogFactory.getLog(getClass());
51+
4752
private Resource resource;
4853

4954
private boolean forceSync = false;
@@ -489,12 +494,16 @@ public FlatFileItemWriter<T> build() {
489494

490495
Assert.isTrue(this.lineAggregator != null || this.delimitedBuilder != null || this.formattedBuilder != null,
491496
"A LineAggregator or a DelimitedBuilder or a FormattedBuilder is required");
492-
Assert.notNull(this.resource, "A Resource is required");
493497

494498
if(this.saveState) {
495499
Assert.hasText(this.name, "A name is required when saveState is true");
496500
}
497501

502+
if(this.resource == null) {
503+
logger.debug("The resource is null. This is only a valid scenario when " +
504+
"injecting it later as in when using the MultiResourceItemWriter");
505+
}
506+
498507
FlatFileItemWriter<T> writer = new FlatFileItemWriter<>();
499508

500509
writer.setName(this.name);

0 commit comments

Comments
 (0)