2016-05-13 7 views
0
<job id="pullPurgeProcessStoreFiles" xmlns="http://www.springframework.org/schema/batch"> 
    <bean id="PullFilesTasklet" class="com.example.PullFilesTasklet" /> 
     <step id="pullFiles" next="validation" > 
      <tasklet ref="PullFilesTasklet"> 
       <skippable-exception-classes> 
        <include class="java.io.FileNotFoundException"/> 
       </skippable-exception-classes> 
      </tasklet> 
     </step>  
</job> 

unten Fehler beim Abruf: ungültiger Inhalt gefunden wurde ab Element skippable-exception-classes.Überspringbare Exception-Klassen auf Tasklet Impementation

Bei der Recherche fand ich, dass skippable-exception-classes innerhalb von Brocken verwendet werden kann. Aber ich muss dasselbe mit ref tablets erreichen.

+0

, durch die Art, wie ich das gleiche mit ref Tasklets erreichen kann? –

Antwort

3

Wenn Sie Skip Exception in Ihrer eigenen Tasklet Implementierung möchten, müssen Sie den Code dazu in Ihrer eigenen Implementierung Tasklet zu schreiben.

Folgen Sie diesem Original thread und bitte Up Abstimmung auf Original-Thread, wenn diese Lösung für Sie arbeitet.

Sie können wie etwas tun

abstract class SkippableTasklet implements Tasklet { 

    //Exceptions that should not cause job status to be BatchStatus.FAILED 
    private List<Class<?>> skippableExceptions; 

    public void setSkippableExceptions(List<Class<?>> skippableExceptions) { 
     this.skippableExceptions = skippableExceptions; 
    } 

    private boolean isSkippable(Exception e) { 
     if (skippableExceptions == null) { 
      return false; 
     } 

     for (Class<?> c : skippableExceptions) { 
      if (e.getClass().isAssignableFrom(c)) { 
       return true; 
      } 
     } 
     return true; 
    } 

    protected abstract void run(JobParameters jobParameters) throws Exception; 

    @Override 
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) 
      throws Exception { 

     StepExecution stepExecution = chunkContext.getStepContext().getStepExecution(); 
     JobExecution jobExecution = stepExecution.getJobExecution(); 
     JobParameters jobParameters = jobExecution.getJobParameters(); 

     try { 
      run(prj); 
     } catch (Exception e) { 
      if (!isSkippable(e)) { 
       throw e; 
      } else { 
       jobExecution.addFailureException(e); 
      } 
     } 

     return RepeatStatus.FINISHED; 
    } 
} 

Und in SpringXML Konfiguration

<batch:tasklet> 
    <bean class="com.MySkippableTasklet" scope="step" autowire="byType"> 
     <property name="skippableExceptions"> 
      <list> 
       <value>org.springframework.mail.MailException</value> 
      </list> 
     </property> 
    </bean> 
</batch:tasklet> 
Verwandte Themen