2014-06-15 72 views
11

我配置的步驟在這樣的XML:可跳過的異常類爲Spring Batch的基於Java配置

<batch:step id="slaveStep"> 
     <batch:tasklet> 
      <batch:chunk 
        reader="reader" 
        processor="processor" 
        writer="writer" 
        commit-interval="10" 
        skip-limit="100000"> 
       <batch:skippable-exception-classes> 
        <batch:include class="MyException"/> 
       </batch:skippable-exception-classes> 
      </batch:chunk> 
     </batch:tasklet> 
    </batch:step> 

Java配置我用StepBuilder這樣的:

@Bean 
public StepBuilder stepBuilder(String stepName) 
{ 
    return new StepBuilder(stepName); 
} 

@Bean 
Step slaveStep() 
{ 
    return stepBuilder("slaveStep") 
      .<Movie, Movie>chunk(10) 
      .reader(reader(new HashMap<>())) 
      .processor(processor()) 
      .writer(writer()) 
      .build(); 
} 

但我可以找不到配置可跳過的異常類的方法

回答

20

您需要使用StepBuilder.faultTolerant方法構建FaultTolerantStepBuilder

return stepBuilder() 
    .chunk() 
    .faultTolerant() 
    .skip(MyException.class) 
    .skipLimit(100000) 
.build() 
+0

感謝您的支持。你能指出我列出的信息在哪裏?我在春季的文檔中搜索過它,但找不到任何提及。 –

+2

請參閱http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/step/builder/StepBuilder.html#chunk-org.springframework.batch.repeat.CompletionPolicy-和http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/step/builder/SimpleStepBuilder.html#faultTolerant--。但說實話,我在查看SB代碼時發現了這種方法 –

1
@Configuration 
@EnableBatchProcessing 
@Import(DataConfig.class) 
    public class SpringBatchConfig { 
    .................. 
    .................. 
    @Autowired 
    private StepBuilderFactory stepBuilders; 

    @Bean 
    public Step loadSlaveStep() 
     return stepBuilders.get("slaveStep")() 
     .chunk() 
     .faultTolerant() 
     .skip(MyException.class) 
     .skipLimit(100000) 
     .build() 
} 
相關問題