I have the following Spring Batch itemwriter that streams to a file, but wish to add a timestamp to the filename.
The following code works but is incorrect, because the timestamp is set at startup time rather than on every batch run.
What I like to achieve is that a new filename gets assigned on every job run, any idea how to do this?
@Component
public class EccAddSumoItemWriter extends SumoStaxEventItemWriter<AddSubscriptionXml> {
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH-mm-ss.SSS");
public EccAddSumoItemWriter(@Value("${sumo.output_folder}") String sumoSavePath) {
setShouldDeleteIfEmpty(true);
setRootIdentification("editionCodeChanged_add");
setResourcePath(sumoSavePath + "/edition_code_changed_add-" + now().format(DATE_FORMATTER) + ".xml");
}
}
setResourcePath merely refers to:
protected void setResourcePath(String resourceFilePath) {
this.setResource(new FileSystemResource(resourceFilePath));
}
What is the advised way of doing this in Spring Batch?
