spring-projects / spring-projects/spring-batch
[Spring-batch Documentation - Configuring for Stop] description is not correct
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
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
- OS : window 10
- jdk : temurin-jdk-21
- spring boot:3.3.4, spring batch core:5.1.2
Steps to reproduce
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
import java.util.List;
@Configuration
@RequiredArgsConstructor
public class MyJobConfig {
private final JobRepository jobRepository;
private final PlatformTransactionManager transactionManager;
@Bean
public Job customItemStreamConfigJob() {
return new JobBuilder("customItemStreamConfigJob", jobRepository)
.start(customItemStreamConfigStep())
.build();
}
@Bean
public Step customItemStreamConfigStep() {
return new StepBuilder("customItemStreamConfigStep", jobRepository)
.<Integer, Integer>chunk(5, transactionManager)
.reader(new ListItemReader<>(List.of())) // give empty List to see EmptyReadFailureListener works properly
.writer(chunk -> chunk.getItems().forEach(System.out::println))
.listener(emptyReadFailureListener())
.build();
}
@Bean
public EmptyReadFailureListener emptyReadFailureListener() {
return new EmptyReadFailureListener();
}
}
The stepExecutionListener( = EmptyReadFailureListener ) code is like below.
package coding.toast.batch.job.simple;
import org.springframework.batch.core.*;
public class EmptyReadFailureListener implements StepExecutionListener {
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
// if there is nothing read from itemReader, Then return ExitStatus.FAILED.
if (stepExecution.getReadCount() > 0) {
return stepExecution.getExitStatus();
} else {
return ExitStatus.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:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the documented stop configuration statement and run the supplied Spring Batch reproduction with the empty ListItemReader and EmptyReadFailureListener. Compare the resulting job and step statuses with the documentation, then correct the documentation so the stated behavior matches the verified result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100