我有以下内容ItemReader
:
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.LineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
@Service
public class MyReader extends FlatFileItemReader<Holding> {
@Autowired
public MyReader(LineMapper<Holding> lineMapper, File loadFile) {
setResource(new FileSystemResource(loadFile));
final int NUMBER_OF_HEADER_LINES = 1;
setLinesToSkip(NUMBER_OF_HEADER_LINES);
setLineMapper(lineMapper);
}
@Override
@Retryable(value=ItemStreamException.class, maxAttempts=5, backoff=@Backoff(delay=1800000))
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
}
}
运行作业时,要读取的文件(即loadFile
)可能可用也可能不可用。如果文件不可用,我希望阅读器休眠约 30 分钟,然后重试打开文件。如果在五次尝试后找不到该文件,它可能会像通常那样通过抛出ItemStreamException
.
不幸的是,上面的代码不会尝试重试打开文件。它在第一次调用 open 时抛出ItemStreamException
,并且不会重试打开。
有人可以解释如何做到这一点吗?注意:我确实@EnableRetry
在SpringBootApplication
上课。