问题陈述:成功完成spring作业后,将无法访问spring批处理分区中设置的ExecutionContext
中的数据。
for (String files : fileNameListmatch) {
ExecutionContext executionContext = new ExecutionContext();
executionContext.putString("file", files);
partitionData.put("partition: " + partitionNo, executionContext);
partitionNo++;
}
在内部分区代码中,我将文件列表添加到ExecutionContext
。
@Value("#{stepExecutionContext['file']}")
String file;
@Override
public void afterJob(JobExecution jobExecution) {
for (String file1 : file) {
moveCSVFile = Files.move(Paths.get(inputFilePath + "/" + file1 + ".csv"),
Paths.get(archiveFilePath + file1 + ".csv"));
moveCTLFile = Files.move(Paths.get(inputFilePath + "/" + file1 + ".ctl"),
Paths.get(archiveFilePath + file1 + ".ctl"));
}
}
在afterJob
内部,我试图在工作完成后从ExecutionContext
访问文件列表。在ExecutionContext
内部获取空。
成功完成工作后,我必须将输入文件移动到另一个文件夹,但是将无法访问文件(在executmentContext中获取null)。工作完成后,我必须将输入文件从一个文件夹移动到另一个文件夹。
有两种不同的执行上下文:一种在步骤级别,另一种在作业级别。确保要使用作业范围的作业,因为您要从作业侦听器访问执行上下文。
如果使用范围限定的步骤,则始终可以使用ExecutionContextPromotionListener
将键提升到作业执行上下文。有关更多详细信息,请参考Passing Data to Future Steps部分。