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
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.batch.item.file.builder;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.batch.item.file.FlatFileFooterCallback;
|
||||
import org.springframework.batch.item.file.FlatFileHeaderCallback;
|
||||
import org.springframework.batch.item.file.FlatFileItemWriter;
|
||||
@@ -32,6 +35,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class FlatFileItemWriterBuilder<T> {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Resource resource;
|
||||
|
||||
private boolean forceSync = false;
|
||||
@@ -242,12 +247,16 @@ public class FlatFileItemWriterBuilder<T> {
|
||||
public FlatFileItemWriter<T> build() {
|
||||
|
||||
Assert.notNull(this.lineAggregator, "A LineAggregator is required");
|
||||
Assert.notNull(this.resource, "A Resource is required");
|
||||
|
||||
if(this.saveState) {
|
||||
Assert.hasText(this.name, "A name is required when saveState is true");
|
||||
}
|
||||
|
||||
if(this.resource == null) {
|
||||
logger.debug("The resource is null. This is only a valid scenario when " +
|
||||
"injecting it later as in when using the MultiResourceItemWriter");
|
||||
}
|
||||
|
||||
FlatFileItemWriter<T> writer = new FlatFileItemWriter<>();
|
||||
|
||||
writer.setName(this.name);
|
||||
|
||||
Reference in New Issue
Block a user