@Bean
@StepScope
public MultiResourceItemReader<PosRow> multiResourceItemReader() {
MultiResourceItemReader<PosRow> resourceItemReader = new MultiResourceItemReader<>();
Resource[] resources = new Resource[0];
String path = "file:" + filePath + File.separator + filePattern + "*";
log.info("Looking for resource files matching {}", path);
try {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
resources = resolver.getResources(path);
} catch (IOException e) {
log.error("Problem with getting resource files ", e);
}
resourceItemReader.setResources(resources);
resourceItemReader.setDelegate(posRowReader());
return resourceItemReader;
}
即使该位置有文件,我也无法获取资源。在前面的步骤中,文件被复制过来,然后我尝试使用PathMatchingResourcePatternResolver
. 我在控制台上打印了以下内容:
c.s.p.p.batch.config.BatchConfiguration : Looking for resource files matching file:C:\Dev\workspace\batch\src\main\resources\localPath\PositionFile*
o.s.b.item.file.MultiResourceItemReader : No resources to read. Set strict=true if this should be an error condition.
我可以看到 locationPattern 构造正确。
filePath
和在文件中filePattern
看起来像这样:application.properties
positionFile.local-path=C:\\Dev\\workspace\\batch\\src\\main\\resources\\localPath
positionFile.patternName=PositionFile