diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java index 152bf3afa2e8..3b823bcda979 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java @@ -22,9 +22,9 @@ import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; +import org.springframework.batch.core.configuration.support.JdbcDefaultBatchConfiguration; import org.springframework.batch.core.converter.JobParametersConverter; -import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.repository.ExecutionContextSerializer; import org.springframework.batch.core.repository.JobRepository; import org.springframework.beans.factory.ObjectProvider; @@ -71,7 +71,7 @@ * @since 1.0.0 */ @AutoConfiguration(after = { HibernateJpaAutoConfiguration.class, TransactionAutoConfiguration.class }) -@ConditionalOnClass({ JobLauncher.class, DataSource.class, DatabasePopulator.class }) +@ConditionalOnClass({ JobOperator.class, DataSource.class, DatabasePopulator.class }) @ConditionalOnBean({ DataSource.class, PlatformTransactionManager.class }) @ConditionalOnMissingBean(value = DefaultBatchConfiguration.class, annotation = EnableBatchProcessing.class) @EnableConfigurationProperties(BatchProperties.class) @@ -81,9 +81,9 @@ public class BatchAutoConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnBooleanProperty(name = "spring.batch.job.enabled", matchIfMissing = true) - public JobLauncherApplicationRunner jobLauncherApplicationRunner(JobLauncher jobLauncher, JobExplorer jobExplorer, + public JobLauncherApplicationRunner jobLauncherApplicationRunner(JobOperator jobOperator, JobRepository jobRepository, BatchProperties properties) { - JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(jobLauncher, jobExplorer, jobRepository); + JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(jobOperator, jobRepository); String jobName = properties.getJob().getName(); if (StringUtils.hasText(jobName)) { runner.setJobName(jobName); @@ -98,7 +98,7 @@ public JobExecutionExitCodeGenerator jobExecutionExitCodeGenerator() { } @Configuration(proxyBeanMethods = false) - static class SpringBootBatchConfiguration extends DefaultBatchConfiguration { + static class SpringBootBatchConfiguration extends JdbcDefaultBatchConfiguration { private final DataSource dataSource; @@ -172,6 +172,7 @@ protected ExecutionContextSerializer getExecutionContextSerializer() { : super.getExecutionContextSerializer(); } + @SuppressWarnings("removal") @Override protected JobParametersConverter getJobParametersConverter() { return (this.jobParametersConverter != null) ? this.jobParametersConverter diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConversionServiceCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConversionServiceCustomizer.java index 925149405d57..d2fa606ce6f5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConversionServiceCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConversionServiceCustomizer.java @@ -16,14 +16,12 @@ package org.springframework.boot.autoconfigure.batch; -import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; 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 - * DefaultBatchConfiguration} while retaining its default auto-configuration. + * {@link ConfigurableConversionService} that is used by the batch infrastructure + * while retaining its default auto-configuration. * * @author Claudio Nave * @since 3.1.0 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionEvent.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionEvent.java index 3c11b2d10a02..b271437c698d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionEvent.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionEvent.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.batch; -import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.job.JobExecution; import org.springframework.context.ApplicationEvent; /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGenerator.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGenerator.java index fb5fce52472e..a71d6741f081 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGenerator.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGenerator.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.job.JobExecution; import org.springframework.boot.ExitCodeGenerator; import org.springframework.context.ApplicationListener; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java index 3b99d2c016e7..3f034f2255c6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java @@ -27,18 +27,18 @@ import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobExecutionException; -import org.springframework.batch.core.JobParameter; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.JobParametersInvalidException; import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverter; -import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.launch.JobLauncher; +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.JobParameter; +import org.springframework.batch.core.job.parameters.JobParameters; +import org.springframework.batch.core.job.parameters.JobParametersBuilder; +import org.springframework.batch.core.job.parameters.JobParametersInvalidException; +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.JobRepository; @@ -55,7 +55,7 @@ import org.springframework.util.StringUtils; /** - * {@link ApplicationRunner} to {@link JobLauncher launch} Spring Batch jobs. If a single + * {@link ApplicationRunner} to {@link JobOperator launch} Spring Batch jobs. If a single * job is found in the context, it will be executed by default. If multiple jobs are * found, launch a specific job by providing a jobName. * @@ -78,9 +78,7 @@ public class JobLauncherApplicationRunner private JobParametersConverter converter = new DefaultJobParametersConverter(); - private final JobLauncher jobLauncher; - - private final JobExplorer jobExplorer; + private final JobOperator jobOperator; private final JobRepository jobRepository; @@ -96,17 +94,14 @@ public class JobLauncherApplicationRunner /** * Create a new {@link JobLauncherApplicationRunner}. - * @param jobLauncher to launch jobs - * @param jobExplorer to check the job repository for previous executions + * @param jobOperator to launch jobs * @param jobRepository to check if a job instance exists with the given parameters * when running a job */ - public JobLauncherApplicationRunner(JobLauncher jobLauncher, JobExplorer jobExplorer, JobRepository jobRepository) { - Assert.notNull(jobLauncher, "'jobLauncher' must not be null"); - Assert.notNull(jobExplorer, "'jobExplorer' must not be null"); + public JobLauncherApplicationRunner(JobOperator jobOperator, JobRepository jobRepository) { + Assert.notNull(jobOperator, "'jobOperator' must not be null"); Assert.notNull(jobRepository, "'jobRepository' must not be null"); - this.jobLauncher = jobLauncher; - this.jobExplorer = jobExplorer; + this.jobOperator = jobOperator; this.jobRepository = jobRepository; } @@ -204,23 +199,24 @@ private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecut } } - protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, - JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { + protected void execute(Job job, JobParameters jobParameters) + throws JobExecutionAlreadyRunningException, NoSuchJobException, JobRestartException, + JobInstanceAlreadyCompleteException, JobParametersInvalidException { JobParameters parameters = getNextJobParameters(job, jobParameters); - JobExecution execution = this.jobLauncher.run(job, parameters); + JobExecution execution = this.jobOperator.start(job, parameters); if (this.publisher != null) { this.publisher.publishEvent(new JobExecutionEvent(execution)); } } 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) { return getNextJobParametersForExisting(job, jobParameters); } if (job.getJobParametersIncrementer() == null) { return jobParameters; } - JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.jobExplorer) + JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.jobRepository) .getNextJobParameters(job) .toJobParameters(); return merge(nextParameters, jobParameters); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index d9446d273d66..82a3f5dc42da 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -29,30 +29,24 @@ import org.mockito.Mockito; import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.Step; -import org.springframework.batch.core.configuration.DuplicateJobException; -import org.springframework.batch.core.configuration.JobFactory; import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.converter.JsonJobParametersConverter; -import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.core.job.AbstractJob; -import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.job.Job; +import org.springframework.batch.core.job.JobExecution; +import org.springframework.batch.core.job.parameters.JobParameters; +import org.springframework.batch.core.job.parameters.JobParametersBuilder; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.repository.ExecutionContextSerializer; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer; import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; -import org.springframework.beans.BeansException; +import org.springframework.batch.core.step.Step; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.DefaultApplicationArguments; @@ -77,7 +71,6 @@ import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.boot.testsupport.classpath.resources.WithResource; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -92,6 +85,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.init.DatabasePopulator; import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.test.util.AopTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Isolation; @@ -124,8 +118,7 @@ class BatchAutoConfigurationTests { void testDefaultContext() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> { assertThat(context).hasSingleBean(JobRepository.class); - assertThat(context).hasSingleBean(JobLauncher.class); - assertThat(context).hasSingleBean(JobExplorer.class); + assertThat(context).hasSingleBean(JobOperator.class); assertThat(context).hasSingleBean(JobRegistry.class); assertThat(context).hasSingleBean(JobOperator.class); assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema()) @@ -164,7 +157,7 @@ void autoConfigurationBacksOffWhenUserProvidesBatchConfiguration() { void testDefinesAndLaunchesJob() { this.contextRunner.withUserConfiguration(JobConfiguration.class, EmbeddedDataSourceConfiguration.class) .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); context.getBean(JobLauncherApplicationRunner.class) .run(new DefaultApplicationArguments("jobParam=test")); JobParameters jobParameters = new JobParametersBuilder().addString("jobParam", "test") @@ -177,7 +170,7 @@ void testDefinesAndLaunchesJob() { void testDefinesAndLaunchesJobIgnoreOptionArguments() { this.contextRunner.withUserConfiguration(JobConfiguration.class, EmbeddedDataSourceConfiguration.class) .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); context.getBean(JobLauncherApplicationRunner.class) .run(new DefaultApplicationArguments("--spring.property=value", "jobParam=test")); JobParameters jobParameters = new JobParametersBuilder().addString("jobParam", "test") @@ -186,19 +179,6 @@ void testDefinesAndLaunchesJobIgnoreOptionArguments() { }); } - @Test - void testDefinesAndLaunchesNamedRegisteredJob() { - this.contextRunner - .withUserConfiguration(NamedJobConfigurationWithRegisteredJob.class, EmbeddedDataSourceConfiguration.class) - .withPropertyValues("spring.batch.job.name:discreteRegisteredJob") - .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); - context.getBean(JobLauncherApplicationRunner.class).run(); - assertThat(context.getBean(JobRepository.class) - .getLastJobExecution("discreteRegisteredJob", new JobParameters())).isNotNull(); - }); - } - @Test void testRegisteredAndLocalJob() { this.contextRunner @@ -206,7 +186,7 @@ void testRegisteredAndLocalJob() { EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.batch.job.name:discreteRegisteredJob") .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); context.getBean(JobLauncherApplicationRunner.class).run(); assertThat(context.getBean(JobRepository.class) .getLastJobExecution("discreteRegisteredJob", new JobParameters()) @@ -220,7 +200,7 @@ void testDefinesAndLaunchesLocalJob() { .withUserConfiguration(NamedJobConfigurationWithLocalJob.class, EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.batch.job.name:discreteLocalJob") .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); context.getBean(JobLauncherApplicationRunner.class).run(); assertThat(context.getBean(JobRepository.class) .getLastJobExecution("discreteLocalJob", new JobParameters())).isNotNull(); @@ -242,7 +222,7 @@ void testMultipleJobsAndJobName() { this.contextRunner.withUserConfiguration(MultipleJobConfiguration.class, EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.batch.job.name:discreteLocalJob") .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); context.getBean(JobLauncherApplicationRunner.class).run(); assertThat(context.getBean(JobRepository.class) .getLastJobExecution("discreteLocalJob", new JobParameters())).isNotNull(); @@ -254,7 +234,7 @@ void testDisableLaunchesJob() { this.contextRunner.withUserConfiguration(JobConfiguration.class, EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.batch.job.enabled:false") .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); assertThat(context).doesNotHaveBean(CommandLineRunner.class); }); } @@ -265,7 +245,7 @@ void testDisableSchemaLoader() { .withPropertyValues("spring.datasource.generate-unique-name=true", "spring.batch.jdbc.initialize-schema:never") .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema()) .isEqualTo(DatabaseInitializationMode.NEVER); assertThat(context).doesNotHaveBean(BatchDataSourceScriptDatabaseInitializer.class); @@ -300,14 +280,13 @@ void testRenamePrefix() { .withPropertyValues("spring.datasource.generate-unique-name=true", "spring.batch.jdbc.schema:classpath:custom-schema.sql", "spring.batch.jdbc.table-prefix:PREFIX_") .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); + assertThat(context).hasSingleBean(JobOperator.class); assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema()) .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty(); - JobExplorer jobExplorer = context.getBean(JobExplorer.class); - assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty(); JobRepository jobRepository = context.getBean(JobRepository.class); + assertThat(jobRepository.findRunningJobExecutions("test")).isEmpty(); assertThat(jobRepository.getLastJobExecution("test", new JobParameters())).isNull(); }); } @@ -376,8 +355,8 @@ void testBatchTaskExecutor() { assertThat(batchTaskExecutor).isInstanceOf(AsyncTaskExecutor.class); assertThat(context.getBean(SpringBootBatchConfiguration.class).getTaskExecutor()) .isEqualTo(batchTaskExecutor); - assertThat(context.getBean(JobLauncher.class)).hasFieldOrPropertyWithValue("taskExecutor", - batchTaskExecutor); + JobOperator jobOperator = AopTestUtils.getTargetObject(context.getBean(JobOperator.class)); + assertThat(jobOperator).hasFieldOrPropertyWithValue("taskExecutor", batchTaskExecutor); }); } @@ -550,8 +529,8 @@ void defaultJobParametersConverterIsUsed() { } private JobLauncherApplicationRunner createInstance(String... registeredJobNames) { - JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(mock(JobLauncher.class), - mock(JobExplorer.class), mock(JobRepository.class)); + JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(mock(JobOperator.class), + mock(JobRepository.class)); JobRegistry jobRegistry = mock(JobRegistry.class); given(jobRegistry.getJobNames()).willReturn(Arrays.asList(registeredJobNames)); runner.setJobRegistry(jobRegistry); @@ -677,75 +656,6 @@ protected void doExecute(JobExecution execution) { } - @Configuration(proxyBeanMethods = false) - static class NamedJobConfigurationWithRegisteredJob { - - @Bean - static BeanPostProcessor registryProcessor(ApplicationContext applicationContext) { - return new NamedJobJobRegistryBeanPostProcessor(applicationContext); - } - - } - - static class NamedJobJobRegistryBeanPostProcessor implements BeanPostProcessor { - - private final ApplicationContext applicationContext; - - NamedJobJobRegistryBeanPostProcessor(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof JobRegistry jobRegistry) { - try { - jobRegistry.register(getJobFactory()); - } - catch (DuplicateJobException ex) { - // Ignore - } - } - return bean; - } - - private JobFactory getJobFactory() { - JobRepository jobRepository = this.applicationContext.getBean(JobRepository.class); - return new JobFactory() { - - @Override - public Job createJob() { - AbstractJob job = new AbstractJob("discreteRegisteredJob") { - - @Override - public Collection getStepNames() { - return Collections.emptySet(); - } - - @Override - public Step getStep(String stepName) { - return null; - } - - @Override - protected void doExecute(JobExecution execution) { - execution.setStatus(BatchStatus.COMPLETED); - } - - }; - job.setJobRepository(jobRepository); - return job; - } - - @Override - public String getJobName() { - return "discreteRegisteredJob"; - } - - }; - } - - } - @Configuration(proxyBeanMethods = false) static class NamedJobConfigurationWithLocalJob { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java index d074a9b15aca..ff6eefffa4d8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java @@ -20,9 +20,8 @@ import org.junit.jupiter.api.Test; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.job.parameters.JobParameters; +import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.repository.JobRepository; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; @@ -57,14 +56,13 @@ void jdbcWithDefaultSettings() { this.contextRunner.withUserConfiguration(DefaultConfiguration.class, EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.datasource.generate-unique-name=true") .run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); - assertThat(context).hasSingleBean(JobExplorer.class); + assertThat(context).hasSingleBean(JobOperator.class); assertThat(context).hasSingleBean(JobRepository.class); assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema()) .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty(); - assertThat(context.getBean(JobExplorer.class).findRunningJobExecutions("test")).isEmpty(); + assertThat(context.getBean(JobRepository.class).findRunningJobExecutions("test")).isEmpty(); assertThat(context.getBean(JobRepository.class).getLastJobExecution("test", new JobParameters())) .isNull(); }); @@ -79,7 +77,7 @@ void jdbcWithCustomPrefix() { .run((context) -> { assertThat(new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty(); - assertThat(context.getBean(JobExplorer.class).findRunningJobExecutions("test")).isEmpty(); + assertThat(context.getBean(JobRepository.class).findRunningJobExecutions("test")).isEmpty(); assertThat(context.getBean(JobRepository.class).getLastJobExecution("test", new JobParameters())) .isNull(); }); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java index e470821b8dbb..ec6c42df58e2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobExecutionExitCodeGeneratorTests.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.job.JobExecution; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java index 2dd1ddc68fef..988358404d9f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java @@ -23,20 +23,20 @@ import org.junit.jupiter.api.Test; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecutionException; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.explore.JobExplorer; +import org.springframework.batch.core.configuration.annotation.EnableJdbcJobRepository; +import org.springframework.batch.core.job.Job; +import org.springframework.batch.core.job.JobExecutionException; +import org.springframework.batch.core.job.JobInstance; import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.job.builder.SimpleJobBuilder; -import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.job.parameters.JobParameters; +import org.springframework.batch.core.job.parameters.JobParametersBuilder; +import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.launch.support.RunIdIncrementer; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; +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.boot.autoconfigure.AutoConfigurations; @@ -181,7 +181,7 @@ static class JobLauncherApplicationRunnerContext { private final JobLauncherApplicationRunner runner; - private final JobExplorer jobExplorer; + private final JobRepository jobRepository; private final JobBuilder jobBuilder; @@ -192,19 +192,19 @@ static class JobLauncherApplicationRunnerContext { private final Step step; JobLauncherApplicationRunnerContext(ApplicationContext context) { - JobLauncher jobLauncher = context.getBean(JobLauncher.class); + JobOperator jobOperator = context.getBean(JobOperator.class); JobRepository jobRepository = context.getBean(JobRepository.class); PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class); this.stepBuilder = new StepBuilder("step", jobRepository); this.step = this.stepBuilder.tasklet((contribution, chunkContext) -> null, transactionManager).build(); this.jobBuilder = new JobBuilder("job", jobRepository); this.job = this.jobBuilder.start(this.step).build(); - this.jobExplorer = context.getBean(JobExplorer.class); - this.runner = new JobLauncherApplicationRunner(jobLauncher, this.jobExplorer, jobRepository); + this.jobRepository = context.getBean(JobRepository.class); + this.runner = new JobLauncherApplicationRunner(jobOperator, jobRepository); } List jobInstances() { - return this.jobExplorer.getJobInstances("job", 0, 100); + return this.jobRepository.getJobInstances("job", 0, 100); } void executeJob(JobParameters jobParameters) throws JobExecutionException { @@ -226,6 +226,7 @@ SimpleJobBuilder configureJob() { } @EnableBatchProcessing + @EnableJdbcJobRepository @Configuration(proxyBeanMethods = false) static class BatchConfiguration { diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index bfbde1a35689..08d5d9dad689 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -2173,7 +2173,7 @@ bom { releaseNotes("https://github.com/spring-projects/spring-authorization-server/releases/tag/{version}") } } - library("Spring Batch", "5.2.2") { + library("Spring Batch", "6.0.0-SNAPSHOT") { considerSnapshots() group("org.springframework.batch") { bom("spring-batch-bom") diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java index d9789f230707..db058f3e28b8 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java @@ -16,10 +16,10 @@ package smoketest.batch; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.Step; +import org.springframework.batch.core.job.Job; import org.springframework.batch.core.job.builder.JobBuilder; 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;