When no file is found, you should skip to the next step (Spring Batch)

Asked

Viewed 208 times

0

I’m using Spring Batch.

In my Job, I have several steps, and they all read from a file. csv.

The problem is as follows, there will be times when the file . csv will not be in the available location for reading. When this happens, an error breaks and Job stops, but I would like him to simply go to the next step.

How can I do that?

2 answers

0

One option is to use the decision tag. For example:

<batch:decision id="decision" decider="decider">
    <batch:next on="FULL" to="fullStep" />
    <batch:next on="FAILED" to="nextStep" />
</batch:decision>

Or, as you can see in documentation.

public class MyDecider implements JobExecutionDecider {
    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
        String status;
        if (someCondition()) {
            status = "FAILED";
        }
        else {
            status = "COMPLETED";
        }
        return new FlowExecutionStatus(status);
    }
}

0

Solution:

In class FlatFileItemReader, just call the method setStrict(false);

By default this value is true. When the value is true and the file is not found, it throws an error and terminates Step with BatchStatus.FAILED.

If the value is false, when an error occurs, it simply terminates Step as BatchStatus.COMPLETED.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.