开发者

Spring Batch FlatFileItemWriter leaves empty file

开发者 https://www.devze.com 2023-02-10 08:33 出处:网络
I have the following code: File overitimeFile = new File(filePath+overtimeFileName); FlatFileItemWriter<OvertimeSAPExport> overtimeItemWriter =

I have the following code:

File overitimeFile = new File(filePath+overtimeFileName);
FlatFileItemWriter<OvertimeSAPExport> overtimeItemWriter = 
                                         new FlatFileItemWriter<OvertimeSAPExport>();
overtimeItemWriter.setResource(new FileSystemResource(overitimeFile));
overtimeItemWriter.setShouldDeleteIfExists(true);
PassThroughLineAggregator<OvertimeSAPExport> lineAggregator = 
                                        new PassThroughLineAggregator<OvertimeSAPExport>();
overtimeItemWriter.setLineAggregator(lineAggregator);
overtimeItemWriter.open(new ExecutionContext());

List<OvertimeSAPExport> overtimeList = overtimeDAO.getSapOvertimeData(locationId, month);
overtimeItemWriter.write(overtimeList);

I have implemented the toString method for OvertimeSAPExport and when I debug I can see that it enters the toString once for each record in the list and gets te correct string from it. It also creates the file without problems and throws no exceptions my way, but when I look at the file, it's empty.

Could someone PLEASE show me where my mista开发者_运维问答ke is?


Try overtimeItemWriter.close(); and see if the file is flushed on disk. You also need to validate if a transaction is ongoing that postponed the writing.

0

精彩评论

暂无评论...
验证码 换一张
取 消