【问题标题】:FlatFileItemReader goes reading same files after processing the filesFlatFileItemReader 处理文件后读取相同的文件
【发布时间】:2015-05-07 05:40:52
【问题描述】:

我正在编写一个 Spring Batch 作业调度程序。我需要为此读取一些特定模式的多个文件,我配置了如下的 xml...

<bean id="multiResourceReader1"
        class=" org.springframework.batch.item.file.MultiResourceItemReader">
        <property name="resources"
            value="file:#{ fileLocation + '/FILE1*.txt'}" />
        <property name="delegate" ref="itemReader1" />
        <property name="saveState" value="false" />
    </bean>
<bean id="itemReader1" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
        <property name="strict" value="false" />
        <property name="lineMapper" ref="prefixMatchingLineMapper1" />
    </bean>

filelocation 是 jndi 字符串值。

问题:当我在每 15 分钟运行一次的应用程序服务器上部署代码时,在读取了 FILE1_2015_03_04.txt 等文件后,处理完成,这些文件将被归档。现在文件位置不有以前的文件或者可能有不同的文件名,但是spring批处理尝试读取相同的文件FILE1_2015_03_04.txt并且警告来了-doOpen“输入资源不存在”。

来自 cmets 的更新 我已经配置了 cron 调度程序,下面是作业的配置:

<batch:job id="ioSampleJob" restartable="false">
  <batch:step id="step1">
    <batch:tasklet>
      <batch:transaction-attributes propagation="NEVER" />
      <batch:chunk reader="multiResourceReader1" writer="itemWriter1" chunk-completion-policy="completionPolicy" /> 
    </batch:tasklet> 
  </batch:step>
</batch:job>

请帮助解决问题。 谢谢维沙尔

【问题讨论】:

  • 如何运行批处理?请同时显示步骤配置
  • 感谢 Michael 的及时评论,我已经配置了 cron 调度程序,下面是作业的配置 - :tasklet>
  • 还想以编程方式添加从 JobDetailBean 中配置的一个 JobLauncher 调用的此作业,并且当前作业中有一个条件可以运行另一个作业程序,谢谢
  • 你能详细说明你的场景吗?意思是说第一次运行和后续运行读取相同的文件?或者在第一次运行时它会重复读取同一个文件,你也可以复制你的 cron 表达式,有时不正确的 cron 表达式配置会同时触发多个作业。
  • 嗨 Karthik,第一个作业通过 JobLaunher 运行,第二个作业在第一个作业运行中满足某些条件时运行,否则只运行第一个作业。

标签: spring spring-batch


【解决方案1】:

我知道有点晚了,但如果你在这里,那是因为你和我一样面临这个问题。 要解决这个问题,你应该在你的 xml 中以单独的方式创建一个 FileSystemResource bean。

<bean id="customFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
    <property name="resource" ref="customFile"/><!-- avoid use directly jobParams here -->
    <property name="linesToSkip" value="0" />
    <property name="encoding" value="ISO-8859-1" />
    <property name="comments" value="*, \u001A" />
    <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="br.com.sample.batch.CustomFieldSetMapperSIAW"/>
            </property>
        </bean>
    </property>
</bean>



<bean id="customFile" class="org.springframework.core.io.FileSystemResource" scope="step">
    <constructor-arg value="#{jobParameters[arquivoGSIN]}"></constructor-arg>
</bean>

【讨论】:

    猜你喜欢
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2020-06-26
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    相关资源
    最近更新 更多