Skip to content

Migrate to Spring Batch 6 #46216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fmbenhassine
Copy link
Contributor

This PR upgrades Spring Boot 4 to Spring Batch 6.

Most of the changes are documented here: https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-6.0-Migration-Guide

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 26, 2025
@philwebb philwebb added type: dependency-upgrade A dependency upgrade and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 26, 2025
@philwebb philwebb modified the milestone: 4.0.x Jun 26, 2025
@snicoll snicoll changed the title Upgrade Spring Batch to version 6 Migrate to Spring Batch 6 Jun 27, 2025
@snicoll snicoll added type: enhancement A general enhancement and removed type: dependency-upgrade A dependency upgrade labels Jun 27, 2025
@snicoll snicoll self-assigned this Jun 27, 2025
@snicoll snicoll modified the milestones: 4.0.x, 4.0.0-M1 Jun 27, 2025
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. There are a number of things we need to fix before going forward. I've added comments.

@@ -172,6 +172,7 @@ protected ExecutionContextSerializer getExecutionContextSerializer() {
: super.getExecutionContextSerializer();
}

@SuppressWarnings("removal")
Copy link
Member

@snicoll snicoll Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what to make of this. The method is deprecated but the class isn't. If we don't want this to be configurable going forward, I'd rather remove the override (and the ObjectProvider)

import org.springframework.core.convert.support.ConfigurableConversionService;

/**
* Callback interface that can be implemented by beans wishing to customize the
* {@link ConfigurableConversionService} that is
* {@link DefaultBatchConfiguration#getConversionService provided by
* {@link JdbcDefaultBatchConfiguration#getConversionService provided by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should relax the javadoc a bit. It looks weird that we refer to that method. Something like

Callback interface that can be implemented by beans wishing to customize the ConfigurableConversionService that is use by the batch infrastructure while retaining its default auto-configuration.

private JobParameters getNextJobParameters(Job job, JobParameters jobParameters) {
if (this.jobRepository != null && this.jobRepository.isJobInstanceExists(job.getName(), jobParameters)) {
if (this.jobRepository != null && this.jobRepository.getJobInstance(job.getName(), jobParameters) != null) {
Copy link
Member

@snicoll snicoll Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something should be adapted in Spring Batch here. JobRepository isn't deprecated but JobExplorer is. The former extends the latter so any method that is not specified in the child is flagged as deprecated.

.getNextJobParameters(job)
.toJobParameters();
return merge(nextParameters, jobParameters);
}

@SuppressWarnings("deprecated")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I see what this suppresses.

@@ -114,6 +107,7 @@
* @author Yanming Zhou
*/
@ExtendWith(OutputCaptureExtension.class)
@SuppressWarnings("removal")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan to deal with those deprecations?

// the following assertion should pass as taskExecutor is inherited from
// TaskExecutorJobLauncher
// assertThat(context.getBean(JobOperator.class)).hasFieldOrPropertyWithValue("taskExecutor",
// batchTaskExecutor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't comment code like that.

The assertion does not pass because context.getBean(JobOperator.class) returns a JDK Proxy. And that proxy does not have such field. We should figure out why it returns a proxy and it didn't before.

@@ -226,6 +227,7 @@ SimpleJobBuilder configureJob() {
}

@EnableBatchProcessing
@EnableJdbcJobRepository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider adding an attribute to @EnableBatchProcessing Looking at the code sample there, it looks odd to me and the second annotation does not make it very obvious it's Spring Batch specific.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I understand it's a bit similar to Spring Session, we can ignore this. I also missed "Job" from the annotation name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants