1

Spring Batchに取り組んでいます:FlatFileからデータを読み取り、Jdbc接続を使用して、ファイルから読み取ったレコードをデータベースに保存しています。その間、データの読み取りまたは書き込み中にエラーが生成された場合に呼び出されるリスナーを構成しました。2つのレコードにエラーがあるデータベースに10のレコードをアップロードしています。必要に応じて8レコードを適切に挿入していますが、onSkipInWrite()メソッドは実際にスキップされた2レコードを出力しませんが、同じ例外を除いて10レコードのバッチ全体を出力します。どのレコードがスキップされていないかをどのように除外すればよいですか。実際には、このメソッドは、バッチ全体でスキップされている正確なレコードを取得することを示しています。私を助けてください....親切な応答を待っています.....ありがとう

Audit.xmlで構成されたサンプル例:

<step id="step1" >
        <tasklet allow-start-if-complete="true">
            <chunk reader="Reader" writer="Writer" commit-interval="10" skip-limit="10">
                <skippable-exception-classes>
                    <include class="java.lang.Exception" />
                </skippable-exception-classes>
            </chunk>
            <listeners>
                <listener ref="Listener" />
            </listeners>
        </tasklet>
    </step>

以下にリスナークラスを作成しました。サンプルは次のとおりです。

public class Listener implements SkipListener {


    @Override
    public void onSkipInProcess(Object item, Throwable throw) {
        System.out.print ("Error in the record :" + item.gettoString() + " Type of Error : " + throw.getClass());

    }

    @Override
    public void onSkipInRead(Throwable throw) {
    }

    @Override
    public void onSkipInWrite(Object item, Throwable throw) {

     System.out.print ("Error in the record :" + item.gettoString() + " Type of Error : " + throw.getClass());

}

} 
4

1 に答える 1

0

それ以外のskip-limit="10"

使用する

                <batch:skip-policy>
                    <bean class="org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy" scope="step"/>
                </batch:skip-policy>
于 2014-03-28T15:22:23.360 に答える