我有一个简单的 spring 批处理作业 - 逐行读取文件,对输入字符串执行某些操作,并写入一些输出 . 输出文件包含每行输入以及该行的某些处理状态(成功/失败 . )从以下位置读取文件:
文件阅读器是这样的:
项目编写器是这样的:
当我运行这个批处理作业时,读者正确读取文件,处理器完成其工作但itemWriter抛出了FileNotFound异常
2014/06/27 18-02-31,168:OUT:ERROR[Encountered an error executing the step]
org.springframework.batch.item.ItemStreamException: Could not convert resource to file: [class path resource [S:/temp/seller-optin-batch/output/sellersToOptin_test.txt]]
at org.springframework.batch.item.file.FlatFileItemWriter.getOutputState(FlatFileItemWriter.java:374)
at org.springframework.batch.item.file.FlatFileItemWriter.open(FlatFileItemWriter.java:314)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: java.io.FileNotFoundException: class path resource [S:/temp/seller-optin-batch/output/sellersToOptin_test.txt] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:179)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:48)
at org.springframework.batch.item.file.FlatFileItemWriter.getOutputState(FlatFileItemWriter.java:371)
... 58 more
2014/06/27 18-02-31,168:ERR:ERROR[Encountered an error executing the step]
[org.springframework.batch.item.file.FlatFileItemWriter.getOutputState threw org.springframework.batch.item.ItemStreamException: Could not convert resource to file: [class path resource [S:/temp/seller-optin-batch/output/sellersToOptin_test.txt]]]
Batch Execution Failed!
每次批处理作业运行时,输出文件都不存在 . itemWriter必须创建它 . 是不是可以使用FlatFileItemWriter?