From 491019d4fe3c93e2e161f772006916d390678abc Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Thu, 9 Oct 2025 17:54:53 +0200 Subject: [PATCH 1/2] Start building against Spring Batch 6.0.0-RC1 snapshots See gh-47477 --- .../JobLauncherApplicationRunner.java | 23 ++++++++++--------- .../JobExecutionExitCodeGeneratorTests.java | 21 +++++++++++------ .../JobLauncherApplicationRunnerTests.java | 2 +- .../spring-boot-dependencies/build.gradle | 2 +- .../batch/SampleBatchApplication.java | 2 +- .../batch/SampleBatchApplication.java | 2 +- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java index 49eafe33c42..37b28c21864 100644 --- a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java +++ b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java @@ -31,13 +31,12 @@ import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.job.Job; import org.springframework.batch.core.job.JobExecution; import org.springframework.batch.core.job.JobExecutionException; +import org.springframework.batch.core.job.parameters.InvalidJobParametersException; import org.springframework.batch.core.job.parameters.JobParameters; -import org.springframework.batch.core.job.parameters.JobParametersInvalidException; +import org.springframework.batch.core.launch.JobExecutionAlreadyRunningException; +import org.springframework.batch.core.launch.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.launch.JobOperator; -import org.springframework.batch.core.launch.NoSuchJobException; -import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; -import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; -import org.springframework.batch.core.repository.JobRestartException; +import org.springframework.batch.core.launch.JobRestartException; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; @@ -146,10 +145,11 @@ public class JobLauncherApplicationRunner public void run(String... args) throws JobExecutionException { logger.info("Running default command line with: " + Arrays.asList(args)); - launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")); + Properties properties = StringUtils.splitArrayElementsIntoProperties(args, "="); + launchJobFromProperties((properties != null) ? properties : new Properties()); } - protected void launchJobFromProperties(@Nullable Properties properties) throws JobExecutionException { + protected void launchJobFromProperties(Properties properties) throws JobExecutionException { JobParameters jobParameters = this.converter.getJobParameters(properties); executeLocalJobs(jobParameters); executeRegisteredJobs(jobParameters); @@ -179,14 +179,15 @@ public class JobLauncherApplicationRunner if (this.jobRegistry != null && StringUtils.hasText(this.jobName)) { if (!isLocalJob(this.jobName)) { Job job = this.jobRegistry.getJob(this.jobName); - execute(job, jobParameters); + if (job != null) { + execute(job, jobParameters); + } } } } - protected void execute(Job job, JobParameters jobParameters) - throws JobExecutionAlreadyRunningException, NoSuchJobException, JobRestartException, - JobInstanceAlreadyCompleteException, JobParametersInvalidException { + protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, + JobRestartException, JobInstanceAlreadyCompleteException, InvalidJobParametersException { JobExecution execution = this.jobOperator.start(job, jobParameters); if (this.publisher != null) { this.publisher.publishEvent(new JobExecutionEvent(execution)); diff --git a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java index d194d4ef307..0c250d0e926 100644 --- a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java +++ b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java @@ -20,6 +20,8 @@ import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.job.JobExecution; +import org.springframework.batch.core.job.JobInstance; +import org.springframework.batch.core.job.parameters.JobParameters; import static org.assertj.core.api.Assertions.assertThat; @@ -27,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link JobExecutionExitCodeGenerator}. * * @author Dave Syer + * @author Mahmoud Ben Hassine */ class JobExecutionExitCodeGeneratorTests { @@ -34,23 +37,27 @@ class JobExecutionExitCodeGeneratorTests { @Test void testExitCodeForRunning() { - this.generator.onApplicationEvent(new JobExecutionEvent(new JobExecution(0L))); + JobInstance jobInstance = new JobInstance(1L, "job"); + JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); + this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); assertThat(this.generator.getExitCode()).isOne(); } @Test void testExitCodeForCompleted() { - JobExecution execution = new JobExecution(0L); - execution.setStatus(BatchStatus.COMPLETED); - this.generator.onApplicationEvent(new JobExecutionEvent(execution)); + JobInstance jobInstance = new JobInstance(1L, "job"); + JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); + jobExecution.setStatus(BatchStatus.COMPLETED); + this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); assertThat(this.generator.getExitCode()).isZero(); } @Test void testExitCodeForFailed() { - JobExecution execution = new JobExecution(0L); - execution.setStatus(BatchStatus.FAILED); - this.generator.onApplicationEvent(new JobExecutionEvent(execution)); + JobInstance jobInstance = new JobInstance(1L, "job"); + JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); + jobExecution.setStatus(BatchStatus.FAILED); + this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); assertThat(this.generator.getExitCode()).isEqualTo(5); } diff --git a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunnerTests.java b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunnerTests.java index 1f49c43c16f..8aeeb37b1dc 100644 --- a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunnerTests.java +++ b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunnerTests.java @@ -33,7 +33,7 @@ import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.Step; import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; +import org.springframework.batch.infrastructure.support.transaction.ResourcelessTransactionManager; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; diff --git a/platform/spring-boot-dependencies/build.gradle b/platform/spring-boot-dependencies/build.gradle index a48f549a56f..a771d8f534d 100644 --- a/platform/spring-boot-dependencies/build.gradle +++ b/platform/spring-boot-dependencies/build.gradle @@ -2372,7 +2372,7 @@ bom { releaseNotes("https://github.com/spring-projects/spring-amqp/releases/tag/v{version}") } } - library("Spring Batch", "6.0.0-M3") { + library("Spring Batch", "6.0.0-SNAPSHOT") { considerSnapshots() group("org.springframework.batch") { bom("spring-batch-bom") diff --git a/smoke-test/spring-boot-smoke-test-batch-jdbc/src/main/java/smoketest/batch/SampleBatchApplication.java b/smoke-test/spring-boot-smoke-test-batch-jdbc/src/main/java/smoketest/batch/SampleBatchApplication.java index db058f3e28b..366dcb7ef7e 100644 --- a/smoke-test/spring-boot-smoke-test-batch-jdbc/src/main/java/smoketest/batch/SampleBatchApplication.java +++ b/smoke-test/spring-boot-smoke-test-batch-jdbc/src/main/java/smoketest/batch/SampleBatchApplication.java @@ -22,7 +22,7 @@ import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.Step; import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.batch.infrastructure.repeat.RepeatStatus; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; diff --git a/smoke-test/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java b/smoke-test/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java index c80a143ed7e..59aa31ec9c3 100644 --- a/smoke-test/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java +++ b/smoke-test/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java @@ -22,7 +22,7 @@ import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.Step; import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.batch.infrastructure.repeat.RepeatStatus; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; From 8cd7c2277f50e98156561044890189dc414737ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Fri, 10 Oct 2025 18:20:22 +0200 Subject: [PATCH 2/2] Polish "Start building against Spring Batch 6.0.0-RC1 snapshots" See gh-47477 --- .../JobLauncherApplicationRunner.java | 5 ++-- .../JobExecutionExitCodeGeneratorTests.java | 24 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java index 37b28c21864..b3c29f846a4 100644 --- a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java +++ b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java @@ -179,9 +179,8 @@ public class JobLauncherApplicationRunner if (this.jobRegistry != null && StringUtils.hasText(this.jobName)) { if (!isLocalJob(this.jobName)) { Job job = this.jobRegistry.getJob(this.jobName); - if (job != null) { - execute(job, jobParameters); - } + Assert.notNull(job, () -> "No job found with name '" + this.jobName + "'"); + execute(job, jobParameters); } } } diff --git a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java index 0c250d0e926..91c0cb0f72b 100644 --- a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java +++ b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java @@ -29,7 +29,6 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link JobExecutionExitCodeGenerator}. * * @author Dave Syer - * @author Mahmoud Ben Hassine */ class JobExecutionExitCodeGeneratorTests { @@ -37,28 +36,29 @@ class JobExecutionExitCodeGeneratorTests { @Test void testExitCodeForRunning() { - JobInstance jobInstance = new JobInstance(1L, "job"); - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); + this.generator.onApplicationEvent(new JobExecutionEvent(testJobExecution())); assertThat(this.generator.getExitCode()).isOne(); } @Test void testExitCodeForCompleted() { - JobInstance jobInstance = new JobInstance(1L, "job"); - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); - jobExecution.setStatus(BatchStatus.COMPLETED); - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); + JobExecution execution = testJobExecution(); + execution.setStatus(BatchStatus.COMPLETED); + this.generator.onApplicationEvent(new JobExecutionEvent(execution)); assertThat(this.generator.getExitCode()).isZero(); } @Test void testExitCodeForFailed() { - JobInstance jobInstance = new JobInstance(1L, "job"); - JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters()); - jobExecution.setStatus(BatchStatus.FAILED); - this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution)); + JobExecution execution = testJobExecution(); + execution.setStatus(BatchStatus.FAILED); + this.generator.onApplicationEvent(new JobExecutionEvent(execution)); assertThat(this.generator.getExitCode()).isEqualTo(5); } + private static JobExecution testJobExecution() { + JobInstance jobInstance = new JobInstance(1L, "job"); + return new JobExecution(0L, jobInstance, new JobParameters()); + } + }