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 によって処理される各行にデータとして追加する) の間で共有されます。

パラメーターとして指定された 1 つのファイルを使用して importOneContractESTD のみを呼び出そうとすると (たとえば、#{stepExecutionContext[inputfile]}${my.file}に置き換えます)、機能します...しかし、Spring バッチを使用して自分の私の呼び出しシェルスクリプトではなくディレクトリ...

あなたのアイデアをありがとう!

4

1 に答える 1