2

我正在尝试开发一个批处理,它可以使用 Spring Batch 处理包含文件的目录。
我查看了MultiResourcePartitioner并尝试了类似的东西:

<job parent="loggerParent" id="importContractESTD" xmlns="http://www.springframework.org/schema/batch">
    <step id="multiImportContractESTD">
        <batch:partition step="partitionImportContractESTD" partitioner="partitioner">
            <batch:handler grid-size="5" task-executor="taskExecutor" />
        </batch:partition>
    </step>
</job>

<bean id="partitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner">
    <property name="keyName" value="inputfile" />
    <property name="resources" value="file:${import.contract.filePattern}" />
</bean>

<step id="partitionImportContractESTD" xmlns="http://www.springframework.org/schema/batch">
    <batch:job ref="importOneContractESTD" job-parameters-extractor="defaultJobParametersExtractor" />
</step>

<bean id="defaultJobParametersExtractor" class="org.springframework.batch.core.step.job.DefaultJobParametersExtractor"
    scope="step" />

<!-- Job importContractESTD definition -->
<job parent="loggerParent" id="importOneContractESTD" xmlns="http://www.springframework.org/schema/batch">
    <step parent="baseStep" id="initStep" next="calculateMD5">
        <tasklet ref="initTasklet" />
    </step>
    <step id="calculateMD5" next="importContract">
        <tasklet ref="md5Tasklet">
            <batch:listeners>
                <batch:listener ref="md5Tasklet" />
            </batch:listeners>
        </tasklet>
    </step>
    <step id="importContract">
        <tasklet>
            <chunk reader="contractReader" processor="contractProcessor" writer="contractWriter" commit-interval="${commit.interval}" />
            <batch:listeners>
                <batch:listener ref="contractProcessor" />
            </batch:listeners>
        </tasklet>
    </step>
</job>

<!-- Chunk definition : Contract ItemReader -->
<bean id="contractReader" class="com.sopra.banking.cirbe.acquisition.batch.AcquisitionFileReader" scope="step">
    <property name="resource" value="#{stepExecutionContext[inputfile]}" />
    <property name="lineMapper">
        <bean id="contractLineMappe" class="org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper">
            <property name="tokenizers">
                <map>
                    <entry key="1*" value-ref="headerTokenizer" />
                    <entry key="2*" value-ref="contractTokenizer" />
                </map>
            </property>
            <property name="fieldSetMappers">
                <map>
                    <entry key="1*" value-ref="headerMapper" />
                    <entry key="2*" value-ref="contractMapper" />
                </map>
            </property>
        </bean>
    </property>
</bean>

<!-- MD5 Tasklet -->
<bean id="md5Tasklet" class="com.sopra.banking.cirbe.acquisition.batch.AcquisitionMD5Tasklet">
    <property name="file" value="#{stepExecutionContext[inputfile]}" />
</bean>

但我得到的是:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'stepExecutionContext' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'

我正在寻找的是一种为file:${import.contract.filePattern}中包含的每个文件启动我的工作importOneContractESTD的方法。并且每个文件在步骤calculateMD5(将处理后的文件md5放入我的jobContext)和步骤importContract(从jobContext读取前一个md5以将其作为数据添加到contractProcessor处理的每一行)之间共享

如果我只尝试使用作为参数给出的一个文件来调用 importOneContractESTD(例如,将#{stepExecutionContext[inputfile]}替换为${my.file}),它可以工作......但我想尝试使用 spring batch 来管理我的目录而不是我的调用shell脚本...

谢谢你的想法!

4

1 回答 1

0

在需要访问 stepExecutionContext 时添加 scope="step"

像这儿:

<bean id="md5Tasklet" class="com.sopra.banking.cirbe.acquisition.batch.AcquisitionMD5Tasklet" scope="step">
    <property name="file" value="#{stepExecutionContext[inputfile]}" />
</bean> 

更多信息在这里

于 2014-02-03T13:12:55.007 回答