Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring batch 可跳过异常_Spring Batch - Fatal编程技术网

Spring batch 可跳过异常

Spring batch 可跳过异常,spring-batch,Spring Batch,我尝试使用以下配置跳过批处理运行期间的所有异常: <chunk reader="aaaFileReader" writer="aaaDBWriter" commit-interval="100" skip-limit="100000"> <skippable-exception-classes> <include class="java.lang.Exceptio

我尝试使用以下配置跳过批处理运行期间的所有异常:

<chunk reader="aaaFileReader" writer="aaaDBWriter"
                commit-interval="100" skip-limit="100000">
                <skippable-exception-classes>
                    <include class="java.lang.Exception" />
                    <exclude
                        class="org.springframework.jdbc.CannotGetJdbcConnectionException" />
                </skippable-exception-classes>

            </chunk>
            <listeners>
                <listener ref="aaabatchFailureListener" />
            </listeners>
根据Spring批处理文档,一些异常不符合可跳过的条件

在您的情况下,从日志中可以清楚地看到,
org.springframework.batch.item.file.FlatFileParseException
不是可跳过的例外,因此重新抛出
org.springframework.batch.core.step.skip.nonskipablereadexception


阅读更多关于以下内容的章节:

对于遇到的任何异常,可跳过性将由类层次结构中最近的超类确定。任何未分类的异常都将被视为“致命”

阅读更多关于这方面的内容,如:

无法跳过读取操作时引发的致命异常

  • 创建自定义文件读取器并重写doRead()方法以始终引发CustomException

    公共类CustomFlatFileItemReader扩展了FlatFileItemReader{ @凌驾 受保护的T doRead()引发异常{ T itemRead=null; 试一试{ itemRead=super.doRead(); }捕获(FlatFileParse异常){ 抛出新的MyException(e.getMessage(),e); } 返回itemRead;} }

  • 覆盖作业跳过策略以始终跳过自定义异常,如下所示:

    .skipPolicy((可丢弃的T,整数skipCount)->{ if(BatchServiceException的T实例) 返回true; 其他的 返回false


  • 您可以在批处理作业配置中添加FlatFileParseException类,例如:

    <batch:chunk reader="customImportReader" writer="customImporter" processor="customProcessor" commit-interval="1" skip-limit="10">
        <batch:skippable-exception-classes>
            <batch:include class="org.springframework.batch.item.file.FlatFileParseException" />
        </batch:skippable-exception-classes>
    </batch:chunk>
    
    
    
    [您可以跳过类似这样的flatfile或NonSkippableReadException异常]()如果不使用XML配置,我发现这很有用:
    <batch:chunk reader="customImportReader" writer="customImporter" processor="customProcessor" commit-interval="1" skip-limit="10">
        <batch:skippable-exception-classes>
            <batch:include class="org.springframework.batch.item.file.FlatFileParseException" />
        </batch:skippable-exception-classes>
    </batch:chunk>