获取Spring批量SkipPolicy中的作业文件名参数 [英] Access job filename parameter in SkipPolicy of Spring Batch
本文介绍了获取Spring批量SkipPolicy中的作业文件名参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用Spring Batch的作业,我使用BeanIO读取一些文件,并且我会处理无效文件,因此我创建了一个SkipPolicy类。
public class FileVerificationSkipper implements SkipPolicy {
private static final FluentLogger LOGGER = LoggerService.init(FileVerificationSkipper.class);
@Override
public boolean shouldSkip(Throwable exception, int skipCount) throws SkipLimitExceededException {
if (exception instanceof FileNotFoundException) {
return false;
}
if (exception instanceof BeanReaderException && skipCount <= 10) {
LOGGER.all().logKey("Error on read file: ").value(exception).asError();
return true;
}
else {
return false;
}
}
}
在我的阅读器步骤中,我访问的名称如下:@Value("#{jobParameters['input.file.name']}") String inputFile
我要记录文件名,如何才能做到这一点?
推荐答案
调试Spring Batch如何注入我找到的解决方案。
我只需要在类中添加@StepScope
,并在要注入参数的位置创建变量:
@Component
@StepScope
@RequiredArgsConstructor
public class FileVerificationSkipper implements SkipPolicy {
@Value("#{jobParameters['input.file.name']}")
private String inputFile;
...
}
这篇关于获取Spring批量SkipPolicy中的作业文件名参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文