Spring batch 在spring批处理中使用FlatFileItemWriter创建新的输出文件

Spring batch 在spring批处理中使用FlatFileItemWriter创建新的输出文件,spring-batch,Spring Batch,我有一个简单的spring批处理作业—逐行读取文件,对输入字符串执行一些操作,并编写一些输出。输出文件包含每一行输入以及该行的一些处理状态(成功/失败)。从以下位置读取文件:/,并将处理后的输出写入/所有这些值都作为作业参数传递 文件读取器是这样的: <bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> <propert

我有一个简单的spring批处理作业—逐行读取文件,对输入字符串执行一些操作,并编写一些输出。输出文件包含每一行输入以及该行的一些处理状态(成功/失败)。从以下位置读取文件:
/
,并将处理后的输出写入
/
所有这些值都作为
作业参数传递
文件读取器是这样的:

<bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
        <property name="resource" value="file:#{jobParameters['cwd']}/#{jobParameters['inputFolder']}/#{jobParameters['inputFile']}" />

        <property name="lineMapper">
          <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">

            <property name="lineTokenizer">
              <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                <property name="delimiter" value="," />
              </bean>
            </property>
            <property name="fieldSetMapper" >
              <bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper" />
            </property>
          </bean>
        </property>
    </bean>

每次批处理作业运行时,输出文件都不存在。itemWriter必须创建它。无法使用FlatFileItemWriter吗?

添加“file://”前缀解决了我的问题。谢谢@LucaBassoRicci。

请尝试使用前缀文件名file://Well,使用ItemWriter绝对可以创建文件;在我看来,要么基本路径不存在,要么您(或您运行的帐户)没有写入权限,要么您的环境使用了错误的路径分隔符。你试过往其他地方写信吗?只需使用一个文件名并省略路径,就可以试一试。@Lucabasoricci:这就是问题所在。谢谢你指出这一点。愚蠢的mistake@Ickster:谢谢。我确实有权限,并且基本路径存在。具有讽刺意味的是,在基于注释的实现中,如果我在正常的文件读取器和写入器用例中使用,它甚至可以在没有
文件的情况下工作://
,但是,当我与partitioner一起使用时,它仍然失败。你是不是碰巧和partitioner一起工作?
<bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step" >
        <property name="resource" value="#{jobParameters['cwd']}/#{jobParameters['outputFolder']}/#{jobParameters['inputFile']}" />
        <property name="lineAggregator">
            <bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
        </property>
    </bean>  
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!