You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am studying Spring Batch using the official documentation. While practicing, I came across a statement explaining that if a step’s ExitStatus is FAILED in a job without a Flow, the job’s Status will also be FAILED.
However, in my tests, even when I returned ExitStatus.FAILED in the afterStep method of a StepExecutionListener, the job’s status was still COMPLETE, contrary to the documentation.
Environment
OS : window 10
jdk : temurin-jdk-21
spring boot:3.3.4, spring batch core:5.1.2
Steps to reproduce
importlombok.RequiredArgsConstructor;
importorg.springframework.batch.core.Job;
importorg.springframework.batch.core.Step;
importorg.springframework.batch.core.job.builder.JobBuilder;
importorg.springframework.batch.core.repository.JobRepository;
importorg.springframework.batch.core.step.builder.StepBuilder;
importorg.springframework.batch.item.support.ListItemReader;
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.Configuration;
importorg.springframework.transaction.PlatformTransactionManager;
importjava.util.List;
@Configuration@RequiredArgsConstructorpublicclassMyJobConfig {
privatefinalJobRepositoryjobRepository;
privatefinalPlatformTransactionManagertransactionManager;
@BeanpublicJobcustomItemStreamConfigJob() {
returnnewJobBuilder("customItemStreamConfigJob", jobRepository)
.start(customItemStreamConfigStep())
.build();
}
@BeanpublicStepcustomItemStreamConfigStep() {
returnnewStepBuilder("customItemStreamConfigStep", jobRepository)
.<Integer, Integer>chunk(5, transactionManager)
.reader(newListItemReader<>(List.of())) // give empty List to see EmptyReadFailureListener works properly
.writer(chunk -> chunk.getItems().forEach(System.out::println))
.listener(emptyReadFailureListener())
.build();
}
@BeanpublicEmptyReadFailureListeneremptyReadFailureListener() {
returnnewEmptyReadFailureListener();
}
}
The stepExecutionListener( = EmptyReadFailureListener ) code is like below.
packagecoding.toast.batch.job.simple;
importorg.springframework.batch.core.*;
publicclassEmptyReadFailureListenerimplementsStepExecutionListener {
@OverridepublicExitStatusafterStep(StepExecutionstepExecution) {
// if there is nothing read from itemReader, Then return ExitStatus.FAILED.if (stepExecution.getReadCount() > 0) {
returnstepExecution.getExitStatus();
} else {
returnExitStatus.FAILED.addExitDescription("exit Because Of No Item Read");
}
}
}
Expected behavior
the job's batch status will be fail.
Test Result
But the Result was different.
the picture under this comment is the result i get after the Spring Batch Execution Ends.
batch_job_execution table:
batch_step_execution table:
The text was updated successfully, but these errors were encountered:
Bug description
I am studying Spring Batch using the official documentation. While practicing, I came across a statement explaining that if a step’s ExitStatus is FAILED in a job without a Flow, the job’s Status will also be FAILED.
However, in my tests, even when I returned ExitStatus.FAILED in the afterStep method of a StepExecutionListener, the job’s status was still COMPLETE, contrary to the documentation.
Environment
Steps to reproduce
The stepExecutionListener( = EmptyReadFailureListener ) code is like below.
Expected behavior
the job's batch status will be fail.
Test Result
But the Result was different.
the picture under this comment is the result i get after the Spring Batch Execution Ends.
batch_job_execution table:
batch_step_execution table:
The text was updated successfully, but these errors were encountered: