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 49eafe33c429..37b28c218640 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.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 void run(ApplicationArguments args) throws Exception { 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 @@ private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecut 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 d194d4ef307a..0c250d0e9264 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.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 @@ * 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 1f49c43c16f7..8aeeb37b1dc3 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.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 432feb33b9e6..6d2409ee9f9d 100644 --- a/platform/spring-boot-dependencies/build.gradle +++ b/platform/spring-boot-dependencies/build.gradle @@ -2369,7 +2369,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 db058f3e28b8..366dcb7ef7e7 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.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 c80a143ed7ea..59aa31ec9c31 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.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;