From 6e443cb1b19bcb83beb657ef9c89e826b775cc0d Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Tue, 13 Sep 2022 16:11:28 +0200 Subject: [PATCH] Deprecate Job/Step builder factories This commit deprecates JobBuilderFactory and StepBuilderFactory in favor of the respective builders they create. It also removes the exposure of such utilities as beans in the application context when using `@EnableBatchProcessing`. Resolves https://github.com/spring-projects/spring-batch/issues/4188 --- .../AbstractBatchConfiguration.java | 33 +----------- .../annotation/EnableBatchProcessing.java | 12 ++--- .../annotation/JobBuilderFactory.java | 3 ++ .../annotation/StepBuilderFactory.java | 3 ++ .../InlineDataSourceDefinitionTests.java | 23 ++++---- .../JobBuilderConfigurationTests.java | 53 ++++++++----------- .../JobLoaderConfigurationTests.java | 40 ++++++-------- .../SimpleJobExplorerIntegrationTests.java | 15 +++--- .../core/job/builder/FlowJobBuilderTests.java | 14 +++-- .../core/job/builder/JobBuilderTests.java | 12 ++--- .../core/listener/ItemListenerErrorTests.java | 19 ++++--- .../core/observability/BatchMetricsTests.java | 32 +++++------ .../builder/RegisterMultiListenerTests.java | 24 ++++----- .../ConcurrentTransactionTests.java | 49 +++++++++-------- .../Db2JobRepositoryIntegrationTests.java | 13 ++--- .../DerbyJobRepositoryIntegrationTests.java | 13 ++--- ...lityModeJobRepositoryIntegrationTests.java | 12 +++-- .../H2JobRepositoryIntegrationTests.java | 13 ++--- .../HANAJobRepositoryIntegrationTests.java | 11 ++-- .../HSQLDBJobRepositoryIntegrationTests.java | 13 ++--- ...ySQLJdbcJobRepositoryIntegrationTests.java | 14 ++--- .../MySQLJobRepositoryIntegrationTests.java | 13 ++--- .../OracleJobRepositoryIntegrationTests.java | 11 ++-- ...stgreSQLJobRepositoryIntegrationTests.java | 13 ++--- ...QLServerJobRepositoryIntegrationTests.java | 13 ++--- .../SQLiteJobRepositoryIntegrationTests.java | 13 ++--- .../SybaseJobRepositoryIntegrationTests.java | 11 ++-- .../FaultTolerantStepIntegrationTests.java | 8 +-- .../config/RetrySampleConfiguration.java | 22 ++++---- .../sample/metrics/Job1Configuration.java | 41 ++++++++------ .../sample/metrics/Job2Configuration.java | 37 ++++++++----- .../mongodb/DeletionJobConfiguration.java | 25 ++++----- .../mongodb/InsertionJobConfiguration.java | 25 ++++----- .../remotechunking/ManagerConfiguration.java | 10 ++-- .../aggregating/ManagerConfiguration.java | 13 ++--- .../polling/ManagerConfiguration.java | 13 ++--- ...SkippableExceptionDuringProcessSample.java | 22 +++----- .../SkippableExceptionDuringReadSample.java | 22 +++----- .../SkippableExceptionDuringWriteSample.java | 22 +++----- .../ValidationSampleConfiguration.java | 22 ++++---- .../sample/JsonSupportIntegrationTests.java | 22 ++++---- .../batch/test/JobLauncherTestUtilsTests.java | 23 ++++---- .../test/SpringBatchTestJUnit4Tests.java | 17 +++--- .../test/SpringBatchTestJUnit5Tests.java | 12 +++-- ...copeAnnotatedListenerIntegrationTests.java | 20 +++---- 45 files changed, 387 insertions(+), 484 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java index 4d75da6ac..6bcf4c108 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java @@ -49,39 +49,15 @@ import org.springframework.transaction.PlatformTransactionManager; */ @Configuration(proxyBeanMethods = false) @Import(ScopeConfiguration.class) -public abstract class AbstractBatchConfiguration implements InitializingBean { +public abstract class AbstractBatchConfiguration { private static final Log logger = LogFactory.getLog(AbstractBatchConfiguration.class); @Autowired protected ApplicationContext context; - private JobBuilderFactory jobBuilderFactory; - - private StepBuilderFactory stepBuilderFactory; - private JobRegistry jobRegistry = new MapJobRegistry(); - /** - * Establish the {@link JobBuilderFactory} for the batch execution. - * @return The instance of the {@link JobBuilderFactory}. - * @throws Exception The {@link Exception} thrown if an error occurs. - */ - @Bean - public JobBuilderFactory jobBuilders() throws Exception { - return this.jobBuilderFactory; - } - - /** - * Establish the {@link StepBuilderFactory} for the batch execution. - * @return The instance of the {@link StepBuilderFactory}. - * @throws Exception The {@link Exception} thrown if an error occurs. - */ - @Bean - public StepBuilderFactory stepBuilders() throws Exception { - return this.stepBuilderFactory; - } - /** * Establish the {@link JobRepository} for the batch execution. * @return The instance of the {@link JobRepository}. @@ -123,13 +99,6 @@ public abstract class AbstractBatchConfiguration implements InitializingBean { */ public abstract PlatformTransactionManager transactionManager() throws Exception; - @Override - public void afterPropertiesSet() throws Exception { - BatchConfigurer batchConfigurer = getOrCreateConfigurer(); - this.jobBuilderFactory = new JobBuilderFactory(batchConfigurer.getJobRepository()); - this.stepBuilderFactory = new StepBuilderFactory(batchConfigurer.getJobRepository()); - } - /** * If a {@link BatchConfigurer} exists, return it. Otherwise, create a * {@link DefaultBatchConfigurer}. If more than one configurer is present, an diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java index 840c53002..16b1c9ec7 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java @@ -44,11 +44,11 @@ import org.springframework.context.annotation.Import; * public class AppConfig { * * @Autowired - * private JobBuilderFactory jobs; + * private JobRepository jobRepository; * * @Bean - * public Job job() { - * return jobs.get("myJob").start(step1()).next(step2()).build(); + * public Job job(JobRepository jobRepository) { + * return new JobBuilder("myJob").repository(jobRepository).start(step1()).next(step2()).build(); * } * * @Bean @@ -108,12 +108,6 @@ import org.springframework.context.annotation.Import; *
  • a {@link org.springframework.batch.core.explore.JobExplorer} (bean name * "jobExplorer" of type * {@link org.springframework.batch.core.explore.support.SimpleJobExplorer})
  • - *
  • a {@link JobBuilderFactory} (bean name "jobBuilders") as a convenience to prevent - * you from having to inject the job repository into every job, as in the earlier - * examples
  • - *
  • a {@link StepBuilderFactory} (bean name "stepBuilders") as a convenience to prevent - * you from having to inject the job repository and transaction manager into every - * step
  • * * * The transaction manager provided by this annotation is of type diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java index ed5768232..92965da77 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java @@ -25,8 +25,11 @@ import org.springframework.util.Assert; * * @author Dave Syer * @author Mahmoud Ben Hassine + * @deprecated Deprecated as of v5.0 and scheduled for removal in v5.2 in favor of using + * the {@link JobBuilder}. * */ +@Deprecated(since = "5.0.0", forRemoval = true) public class JobBuilderFactory { private JobRepository jobRepository; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java index ea56a6ee8..e7f76ba86 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java @@ -26,8 +26,11 @@ import org.springframework.util.Assert; * * @author Dave Syer * @author Mahmoud Ben Hassine + * @deprecated Deprecated as of v5.0 and scheduled for removal in v5.2 in favor of using + * the {@link StepBuilder}. * */ +@Deprecated(since = "5.0.0", forRemoval = true) public class StepBuilderFactory { private JobRepository jobRepository; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java index 20d526216..e1517683f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java @@ -24,7 +24,10 @@ import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -53,21 +56,13 @@ class InlineDataSourceDefinitionTests { @EnableBatchProcessing static class MyJobConfiguration { - private JobBuilderFactory jobs; - - private StepBuilderFactory steps; - - public MyJobConfiguration(JobBuilderFactory jobs, StepBuilderFactory steps) { - this.jobs = jobs; - this.steps = steps; - } - @Bean - public Job job() { - return jobs.get("job").start(steps.get("step").tasklet((contribution, chunkContext) -> { - System.out.println("hello world"); - return RepeatStatus.FINISHED; - }).build()).build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository).tasklet((contribution, chunkContext) -> { + System.out.println("hello world"); + return RepeatStatus.FINISHED; + }).build()).build(); } @Bean diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java index 97e539689..fcb65ea29 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java @@ -29,10 +29,13 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; +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.repository.JobRepository; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.AbstractStep; +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.beans.factory.annotation.Autowired; @@ -110,28 +113,28 @@ public class JobBuilderConfigurationTests { public static class TestConfiguration { @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; + private JobRepository jobRepository; @Autowired private JdbcTransactionManager transactionManager; @Bean public Job testJob() throws Exception { - SimpleJobBuilder builder = jobs.get("test").start(step1()).next(step2()); + SimpleJobBuilder builder = new JobBuilder("test").repository(this.jobRepository).start(step1()) + .next(step2()); return builder.build(); } @Bean protected Step step1() throws Exception { - return steps.get("step1").tasklet(tasklet()).transactionManager(this.transactionManager).build(); + return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet()) + .transactionManager(this.transactionManager).build(); } @Bean protected Step step2() throws Exception { - return steps.get("step2").tasklet(tasklet()).transactionManager(this.transactionManager).build(); + return new StepBuilder("step2").repository(jobRepository).tasklet(tasklet()) + .transactionManager(this.transactionManager).build(); } @Bean @@ -155,12 +158,6 @@ public class JobBuilderConfigurationTests { @Import(DataSourceConfiguration.class) public static class AnotherConfiguration { - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - @Autowired private JdbcTransactionManager transactionManager; @@ -168,14 +165,15 @@ public class JobBuilderConfigurationTests { private Tasklet tasklet; @Bean - public Job anotherJob() throws Exception { - SimpleJobBuilder builder = jobs.get("another").start(step3()); + public Job anotherJob(JobRepository jobRepository) throws Exception { + SimpleJobBuilder builder = new JobBuilder("another").repository(jobRepository).start(step3(jobRepository)); return builder.build(); } @Bean - protected Step step3() throws Exception { - return steps.get("step3").tasklet(tasklet).transactionManager(this.transactionManager).build(); + protected Step step3(JobRepository jobRepository) throws Exception { + return new StepBuilder("step3").repository(jobRepository).tasklet(tasklet) + .transactionManager(this.transactionManager).build(); } } @@ -185,16 +183,13 @@ public class JobBuilderConfigurationTests { @Import(DataSourceConfiguration.class) public static class TestConfigurer extends DefaultBatchConfigurer { - @Autowired - private SimpleBatchConfiguration jobs; - public TestConfigurer(DataSource dataSource) { super(dataSource); } @Bean - public Job testConfigurerJob() throws Exception { - SimpleJobBuilder builder = jobs.jobBuilders().get("configurer").start(step1()); + public Job testConfigurerJob(JobRepository jobRepository) throws Exception { + SimpleJobBuilder builder = new JobBuilder("configurer").repository(jobRepository).start(step1()); return builder.build(); } @@ -218,24 +213,18 @@ public class JobBuilderConfigurationTests { @Import(DataSourceConfiguration.class) public static class BeansConfigurer { - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - @Autowired private JdbcTransactionManager transactionManager; @Bean - public Job beansConfigurerJob() throws Exception { - SimpleJobBuilder builder = jobs.get("beans").start(step1()); + public Job beansConfigurerJob(JobRepository jobRepository) throws Exception { + SimpleJobBuilder builder = new JobBuilder("beans").repository(jobRepository).start(step1(jobRepository)); return builder.build(); } @Bean - protected Step step1() throws Exception { - return steps.get("step1").tasklet(new Tasklet() { + protected Step step1(JobRepository jobRepository) throws Exception { + return new StepBuilder("step1").repository(jobRepository).tasklet(new Tasklet() { @Nullable @Override diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java index 864cc0889..88709114a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java @@ -32,9 +32,12 @@ import org.springframework.batch.core.configuration.support.ApplicationContextFa import org.springframework.batch.core.configuration.support.AutomaticJobRegistrar; import org.springframework.batch.core.configuration.support.GenericApplicationContextFactory; import org.springframework.batch.core.explore.JobExplorer; +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.repository.JobRepository; import org.springframework.batch.core.scope.context.ChunkContext; +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.support.transaction.ResourcelessTransactionManager; @@ -122,28 +125,23 @@ class JobLoaderConfigurationTests { }; } - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - @Bean - public Job testJob() throws Exception { - SimpleJobBuilder builder = jobs.get("test").start(step1()).next(step2()); + public Job testJob(JobRepository jobRepository) throws Exception { + SimpleJobBuilder builder = new JobBuilder("test").repository(jobRepository).start(step1(jobRepository)) + .next(step2(jobRepository)); return builder.build(); } @Bean - protected Step step1() throws Exception { - return steps.get("step1").tasklet(tasklet()).transactionManager(new ResourcelessTransactionManager()) - .build(); + protected Step step1(JobRepository jobRepository) throws Exception { + return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet()) + .transactionManager(new ResourcelessTransactionManager()).build(); } @Bean - protected Step step2() throws Exception { - return steps.get("step2").tasklet(tasklet()).transactionManager(new ResourcelessTransactionManager()) - .build(); + protected Step step2(JobRepository jobRepository) throws Exception { + return new StepBuilder("step2").repository(jobRepository).tasklet(tasklet()) + .transactionManager(new ResourcelessTransactionManager()).build(); } @Bean @@ -162,21 +160,15 @@ class JobLoaderConfigurationTests { @Configuration public static class VanillaConfiguration { - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - @Bean - public Job vanillaJob() throws Exception { - SimpleJobBuilder builder = jobs.get("vanilla").start(step3()); + public Job vanillaJob(JobRepository jobRepository) throws Exception { + SimpleJobBuilder builder = new JobBuilder("vanilla").repository(jobRepository).start(step3(jobRepository)); return builder.build(); } @Bean - protected Step step3() throws Exception { - return steps.get("step3").tasklet(new Tasklet() { + protected Step step3(JobRepository jobRepository) throws Exception { + return new StepBuilder("step3").repository(jobRepository).tasklet(new Tasklet() { @Nullable @Override public RepeatStatus execute(StepContribution contribution, ChunkContext context) throws Exception { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java index 42acc89af..048b79183 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java @@ -32,10 +32,9 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.xml.DummyStep; import org.springframework.batch.core.explore.JobExplorer; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.job.flow.FlowExecutionStatus; import org.springframework.batch.core.job.flow.FlowStep; import org.springframework.batch.core.job.flow.support.SimpleFlow; @@ -47,6 +46,7 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -74,9 +74,6 @@ class SimpleJobExplorerIntegrationTests { @EnableBatchProcessing static class Config { - @Autowired - private StepBuilderFactory steps; - @Bean public JobExplorer jobExplorer() throws Exception { return jobExplorerFactoryBean().getObject(); @@ -90,8 +87,8 @@ class SimpleJobExplorerIntegrationTests { } @Bean - public Step flowStep() { - return steps.get("flowStep").flow(simpleFlow()).build(); + public Step flowStep(JobRepository jobRepository) { + return new StepBuilder("flowStep").repository(jobRepository).flow(simpleFlow()).build(); } @Bean @@ -131,8 +128,8 @@ class SimpleJobExplorerIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobBuilderFactory) { - return jobBuilderFactory.get("job").start(dummyStep()).build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(dummyStep()).build(); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java index 800dca4d7..3787c6be3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java @@ -34,9 +34,7 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.JobScope; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.job.flow.Flow; import org.springframework.batch.core.job.flow.FlowExecutionStatus; import org.springframework.batch.core.job.flow.JobExecutionDecider; @@ -44,6 +42,7 @@ import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.item.support.ListItemReader; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; @@ -290,19 +289,18 @@ class FlowJobBuilderTests { @Bean @JobScope - public Step step(StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager, + public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager, @Value("#{jobParameters['chunkSize']}") Integer chunkSize) { - return stepBuilderFactory.get("step").chunk(chunkSize) + return new StepBuilder("step").repository(jobRepository).chunk(chunkSize) .transactionManager(transactionManager).reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4))) .writer(items -> { }).build(); } @Bean - public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory, - PlatformTransactionManager transactionManager) { - Step step = step(stepBuilderFactory, transactionManager, null); - return jobBuilderFactory.get("job").flow(step).build().build(); + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + Step step = step(jobRepository, transactionManager, null); + return new JobBuilder("job").repository(jobRepository).flow(step).build().build(); } @Bean diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java index 7b5a3f19e..bc8e60d51 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java @@ -27,9 +27,9 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.annotation.AfterJob; import org.springframework.batch.core.annotation.BeforeJob; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -70,11 +70,11 @@ class JobBuilderTests { static class MyJobConfiguration { @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job").listener(new InterfaceBasedJobExecutionListener()) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository).listener(new InterfaceBasedJobExecutionListener()) .listener(new AnnotationBasedJobExecutionListener()) - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java index 666352d8e..b9d76c39e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java @@ -33,10 +33,11 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.support.RunIdIncrementer; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.item.Chunk; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; @@ -131,18 +132,20 @@ class ItemListenerErrorTests { public static class BatchConfiguration { @Bean - public Job testJob(JobBuilderFactory jobs, Step testStep) { - return jobs.get("testJob").incrementer(new RunIdIncrementer()).start(testStep).build(); + public Job testJob(JobRepository jobRepository, Step testStep) { + return new JobBuilder("testJob").repository(jobRepository).incrementer(new RunIdIncrementer()) + .start(testStep).build(); } @Bean - public Step step1(StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager, + public Step step1(JobRepository jobRepository, PlatformTransactionManager transactionManager, ItemReader fakeItemReader, ItemProcessor fakeProcessor, ItemWriter fakeItemWriter, ItemProcessListener itemProcessListener) { - return stepBuilderFactory.get("testStep").chunk(10).transactionManager(transactionManager) - .reader(fakeItemReader).processor(fakeProcessor).writer(fakeItemWriter) - .listener(itemProcessListener).faultTolerant().skipLimit(50).skip(RuntimeException.class).build(); + return new StepBuilder("testStep").repository(jobRepository).chunk(10) + .transactionManager(transactionManager).reader(fakeItemReader).processor(fakeProcessor) + .writer(fakeItemWriter).listener(itemProcessListener).faultTolerant().skipLimit(50) + .skip(RuntimeException.class).build(); } @Bean diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java index 09c6ae22a..b63e157d4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java @@ -35,9 +35,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +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.batch.repeat.RepeatStatus; import org.springframework.context.ApplicationContext; @@ -222,36 +223,30 @@ class BatchMetricsTests { @Import(DataSoourceConfiguration.class) static class MyJobConfiguration { - private JobBuilderFactory jobBuilderFactory; - - private StepBuilderFactory stepBuilderFactory; - private PlatformTransactionManager transactionManager; - public MyJobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory, - PlatformTransactionManager transactionManager) { - this.jobBuilderFactory = jobBuilderFactory; - this.stepBuilderFactory = stepBuilderFactory; + public MyJobConfiguration(PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; } @Bean - public Step step1() { - return stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Step step1(JobRepository jobRepository) { + return new StepBuilder("step1").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(this.transactionManager).build(); } @Bean - public Step step2() { - return stepBuilderFactory.get("step2").chunk(2) + public Step step2(JobRepository jobRepository) { + return new StepBuilder("step2").repository(jobRepository).chunk(2) .transactionManager(this.transactionManager) .reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4, 5))) .writer(items -> items.forEach(System.out::println)).build(); } @Bean - public Step step3() { - return stepBuilderFactory.get("step3").chunk(2) + public Step step3(JobRepository jobRepository) { + return new StepBuilder("step3").repository(jobRepository).chunk(2) .transactionManager(this.transactionManager) .reader(new ListItemReader<>(Arrays.asList(6, 7, 8, 9, 10))) .writer(items -> items.forEach(System.out::println)).faultTolerant().skip(Exception.class) @@ -259,8 +254,9 @@ class BatchMetricsTests { } @Bean - public Job job() { - return jobBuilderFactory.get("job").start(step1()).next(step2()).next(step3()).build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(step1(jobRepository)) + .next(step2(jobRepository)).next(step3(jobRepository)).build(); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java index 2bd23d213..cafa55b5b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java @@ -34,9 +34,9 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.item.Chunk; import org.springframework.batch.item.ItemReader; @@ -128,15 +128,9 @@ class RegisterMultiListenerTests { public static abstract class MultiListenerTestConfigurationSupport { - @Autowired - protected JobBuilderFactory jobBuilders; - - @Autowired - protected StepBuilderFactory stepBuilders; - @Bean - public Job testJob() { - return jobBuilders.get("testJob").start(step()).build(); + public Job testJob(JobRepository jobRepository) { + return new JobBuilder("testJob").repository(jobRepository).start(step(jobRepository)).build(); } @Bean @@ -186,7 +180,7 @@ class RegisterMultiListenerTests { }; } - public abstract Step step(); + public abstract Step step(JobRepository jobRepository); } @@ -209,8 +203,8 @@ class RegisterMultiListenerTests { @Override @Bean - public Step step() { - return stepBuilders.get("step").listener(listener()).chunk(2) + public Step step(JobRepository jobRepository) { + return new StepBuilder("step").repository(jobRepository).listener(listener()).chunk(2) .transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer()) .faultTolerant().skipLimit(1).skip(MySkippableException.class) // ChunkListener registered twice for checking BATCH-2149 @@ -238,8 +232,8 @@ class RegisterMultiListenerTests { @Override @Bean - public Step step() { - return stepBuilders.get("step").listener(listener()).chunk(2) + public Step step(JobRepository jobRepository) { + return new StepBuilder("step").repository(jobRepository).listener(listener()).chunk(2) .transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer()).build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java index 0e76e6716..f5e2a701a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java @@ -31,14 +31,14 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.job.builder.FlowBuilder; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.job.flow.Flow; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.scope.context.ChunkContext; +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.beans.factory.annotation.Autowired; @@ -90,12 +90,6 @@ class ConcurrentTransactionTests { @Import(DataSourceConfiguration.class) public static class ConcurrentJobConfiguration extends DefaultBatchConfigurer { - @Autowired - private JobBuilderFactory jobBuilderFactory; - - @Autowired - private StepBuilderFactory stepBuilderFactory; - public ConcurrentJobConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) { super(dataSource, transactionManager); } @@ -106,15 +100,17 @@ class ConcurrentTransactionTests { } @Bean - public Flow flow() { - return new FlowBuilder("flow").start(stepBuilderFactory.get("flow.step1").tasklet(new Tasklet() { - @Nullable - @Override - public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - return RepeatStatus.FINISHED; - } - }).transactionManager(getTransactionManager()).build()) - .next(stepBuilderFactory.get("flow.step2").tasklet(new Tasklet() { + public Flow flow(JobRepository jobRepository) { + return new FlowBuilder("flow") + .start(new StepBuilder("flow.step1").repository(jobRepository).tasklet(new Tasklet() { + @Nullable + @Override + public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) + throws Exception { + return RepeatStatus.FINISHED; + } + }).transactionManager(getTransactionManager()).build()) + .next(new StepBuilder("flow.step2").repository(jobRepository).tasklet(new Tasklet() { @Nullable @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) @@ -125,8 +121,8 @@ class ConcurrentTransactionTests { } @Bean - public Step firstStep() { - return stepBuilderFactory.get("firstStep").tasklet(new Tasklet() { + public Step firstStep(JobRepository jobRepository) { + return new StepBuilder("firstStep").repository(jobRepository).tasklet(new Tasklet() { @Nullable @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { @@ -137,8 +133,8 @@ class ConcurrentTransactionTests { } @Bean - public Step lastStep() { - return stepBuilderFactory.get("lastStep").tasklet(new Tasklet() { + public Step lastStep(JobRepository jobRepository) { + return new StepBuilder("lastStep").repository(jobRepository).tasklet(new Tasklet() { @Nullable @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { @@ -149,12 +145,15 @@ class ConcurrentTransactionTests { } @Bean - public Job concurrentJob() { + public Job concurrentJob(JobRepository jobRepository) { Flow splitFlow = new FlowBuilder("splitflow").split(new SimpleAsyncTaskExecutor()) - .add(flow(), flow(), flow(), flow(), flow(), flow(), flow()).build(); + .add(flow(jobRepository), flow(jobRepository), flow(jobRepository), flow(jobRepository), + flow(jobRepository), flow(jobRepository), flow(jobRepository)) + .build(); - return jobBuilderFactory.get("concurrentJob").start(firstStep()) - .next(stepBuilderFactory.get("splitFlowStep").flow(splitFlow).build()).next(lastStep()).build(); + return new JobBuilder("concurrentJob").repository(jobRepository).start(firstStep(jobRepository)) + .next(new StepBuilder("splitFlowStep").repository(jobRepository).flow(splitFlow).build()) + .next(lastStep(jobRepository)).build(); } @Override diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java index 53894fbcf..59f3c33d1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java @@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -112,10 +113,10 @@ class Db2JobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java index ec505b1b6..2e7c3419b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java @@ -25,9 +25,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -82,10 +83,10 @@ class DerbyJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java index de54ec273..402dd0cc4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java @@ -27,9 +27,10 @@ import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -91,9 +92,10 @@ class H2CompatibilityModeJobRepositoryIntegrationTests { } @Bean - Job job(JobBuilderFactory jobs, StepBuilderFactory steps, PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java index 7281108cf..4220842ca 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java @@ -25,9 +25,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -82,10 +83,10 @@ class H2JobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java index 888f9f36f..cbfd8d954 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java @@ -33,9 +33,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -120,9 +121,9 @@ class HANAJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build()) + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step") + .repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java index d65085fab..987ea321f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java @@ -25,9 +25,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -82,10 +83,10 @@ class HSQLDBJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java index 6eba4326d..979483e8e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java @@ -34,14 +34,14 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor; import org.springframework.batch.core.explore.JobExplorer; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.launch.support.SimpleJobOperator; import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -138,11 +138,11 @@ class MySQLJdbcJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job").start(steps.get("step").tasklet((contribution, chunkContext) -> { - throw new Exception("expected failure"); - }).transactionManager(transactionManager).build()).build(); + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository).tasklet((contribution, chunkContext) -> { + throw new Exception("expected failure"); + }).transactionManager(transactionManager).build()).build(); } @Bean diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java index 2f19a4cc7..5a210b31d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java @@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -109,10 +110,10 @@ class MySQLJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java index 70376d613..d3ee2cfb6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java @@ -32,9 +32,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -110,9 +111,9 @@ class OracleJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build()) + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step") + .repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java index 7ea53c9e1..cb7f427a1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java @@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -108,10 +109,10 @@ class PostgreSQLJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java index 26387f6e8..a3cf585f9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java @@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -109,10 +110,10 @@ class SQLServerJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java index 05a76fe17..7662c0e99 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java @@ -26,9 +26,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -89,10 +90,10 @@ class SQLiteJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, - PlatformTransactionManager transactionManager) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java index a0879a7f6..c46222861 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java @@ -28,9 +28,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -104,9 +105,9 @@ class SybaseJobRepositoryIntegrationTests { } @Bean - public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) { - return jobs.get("job") - .start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build()) + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step") + .repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build()) .build(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java index 4eb34611e..59231241d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java @@ -29,9 +29,9 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.builder.FaultTolerantStepBuilder; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy; import org.springframework.batch.core.step.skip.SkipLimitExceededException; import org.springframework.batch.core.step.skip.SkipPolicy; @@ -77,7 +77,7 @@ class FaultTolerantStepIntegrationTests { } }; skipPolicy = new SkipIllegalArgumentExceptionSkipPolicy(); - stepBuilder = new StepBuilderFactory(jobRepository).get("step").chunk(CHUNK_SIZE) + stepBuilder = new StepBuilder("step").repository(jobRepository).chunk(CHUNK_SIZE) .transactionManager(transactionManager).reader(itemReader).processor(item -> item > 20 ? null : item) .writer(itemWriter).faultTolerant(); } @@ -178,7 +178,7 @@ class FaultTolerantStepIntegrationTests { } }; - Step step = new StepBuilderFactory(jobRepository).get("step").chunk(5) + Step step = new StepBuilder("step").repository(jobRepository).chunk(5) .transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter) .faultTolerant().skip(Exception.class).skipLimit(3).build(); @@ -218,7 +218,7 @@ class FaultTolerantStepIntegrationTests { } }; - Step step = new StepBuilderFactory(jobRepository).get("step").chunk(5) + Step step = new StepBuilder("step").repository(jobRepository).chunk(5) .transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter) .faultTolerant().skipPolicy(new AlwaysSkipItemSkipPolicy()).build(); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java index eb38f8a10..d721c1eb3 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java @@ -18,8 +18,9 @@ package org.springframework.batch.sample.config; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.ItemReader; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.sample.domain.trade.Trade; @@ -39,24 +40,19 @@ import org.springframework.transaction.PlatformTransactionManager; @EnableBatchProcessing public class RetrySampleConfiguration { - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - @Autowired private PlatformTransactionManager transactionManager; @Bean - public Job retrySample() { - return jobs.get("retrySample").start(step()).build(); + public Job retrySample(JobRepository jobRepository) { + return new JobBuilder("retrySample").repository(jobRepository).start(step(jobRepository)).build(); } @Bean - protected Step step() { - return steps.get("step").chunk(1).transactionManager(this.transactionManager).reader(reader()) - .writer(writer()).faultTolerant().retry(Exception.class).retryLimit(3).build(); + protected Step step(JobRepository jobRepository) { + return new StepBuilder("step").repository(jobRepository).chunk(1) + .transactionManager(this.transactionManager).reader(reader()).writer(writer()).faultTolerant() + .retry(Exception.class).retryLimit(3).build(); } @Bean diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java index 129e66070..7bdc605d5 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java @@ -1,11 +1,27 @@ +/* + * Copyright 2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.batch.sample.metrics; import java.util.Random; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.repeat.RepeatStatus; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -15,24 +31,19 @@ public class Job1Configuration { private Random random; - private JobBuilderFactory jobs; - - private StepBuilderFactory steps; - - public Job1Configuration(JobBuilderFactory jobs, StepBuilderFactory steps) { - this.jobs = jobs; - this.steps = steps; + public Job1Configuration() { this.random = new Random(); } @Bean - public Job job1() { - return jobs.get("job1").start(step1()).next(step2()).build(); + public Job job1(JobRepository jobRepository) { + return new JobBuilder("job1").repository(jobRepository).start(step1(jobRepository)).next(step2(jobRepository)) + .build(); } @Bean - public Step step1() { - return steps.get("step1").tasklet((contribution, chunkContext) -> { + public Step step1(JobRepository jobRepository) { + return new StepBuilder("step1").repository(jobRepository).tasklet((contribution, chunkContext) -> { System.out.println("hello"); // simulate processing time Thread.sleep(random.nextInt(3000)); @@ -41,8 +52,8 @@ public class Job1Configuration { } @Bean - public Step step2() { - return steps.get("step2").tasklet((contribution, chunkContext) -> { + public Step step2(JobRepository jobRepository) { + return new StepBuilder("step2").repository(jobRepository).tasklet((contribution, chunkContext) -> { System.out.println("world"); // simulate step failure int nextInt = random.nextInt(3000); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java index bf6865b82..330aedd0d 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java @@ -1,3 +1,18 @@ +/* + * Copyright 2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.batch.sample.metrics; import java.util.LinkedList; @@ -6,9 +21,10 @@ import java.util.Random; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepScope; +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.ItemWriter; import org.springframework.batch.item.support.ListItemReader; import org.springframework.context.annotation.Bean; @@ -19,24 +35,19 @@ public class Job2Configuration { private Random random; - private JobBuilderFactory jobs; - - private StepBuilderFactory steps; - - public Job2Configuration(JobBuilderFactory jobs, StepBuilderFactory steps) { - this.jobs = jobs; - this.steps = steps; + public Job2Configuration() { this.random = new Random(); } @Bean - public Job job2() { - return jobs.get("job2").start(step()).build(); + public Job job2(JobRepository jobRepository) { + return new JobBuilder("job2").repository(jobRepository).start(step(jobRepository)).build(); } @Bean - public Step step() { - return steps.get("step1").chunk(3).reader(itemReader()).writer(itemWriter()).build(); + public Step step(JobRepository jobRepository) { + return new StepBuilder("step1").repository(jobRepository).chunk(3).reader(itemReader()) + .writer(itemWriter()).build(); } @Bean diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java index 6528ecad9..d88e90a9b 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,9 @@ import java.util.Map; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.data.MongoItemReader; import org.springframework.batch.item.data.MongoItemWriter; import org.springframework.batch.item.data.builder.MongoItemReaderBuilder; @@ -43,15 +44,6 @@ import static org.springframework.data.mongodb.core.query.Criteria.where; @EnableBatchProcessing public class DeletionJobConfiguration { - private JobBuilderFactory jobBuilderFactory; - - private StepBuilderFactory stepBuilderFactory; - - public DeletionJobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) { - this.jobBuilderFactory = jobBuilderFactory; - this.stepBuilderFactory = stepBuilderFactory; - } - @Bean public MongoItemReader mongoPersonReader(MongoTemplate mongoTemplate) { Map sortOptions = new HashMap<>(); @@ -68,14 +60,15 @@ public class DeletionJobConfiguration { } @Bean - public Step deletionStep(MongoItemReader mongoPersonReader, MongoItemWriter mongoPersonRemover) { - return this.stepBuilderFactory.get("step").chunk(2).reader(mongoPersonReader) + public Step deletionStep(JobRepository jobRepository, MongoItemReader mongoPersonReader, + MongoItemWriter mongoPersonRemover) { + return new StepBuilder("step").repository(jobRepository).chunk(2).reader(mongoPersonReader) .writer(mongoPersonRemover).build(); } @Bean - public Job deletionJob(Step deletionStep) { - return this.jobBuilderFactory.get("deletionJob").start(deletionStep).build(); + public Job deletionJob(JobRepository jobRepository, Step deletionStep) { + return new JobBuilder("deletionJob").repository(jobRepository).start(deletionStep).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java index ae9c56e9d..5dc07dd7c 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,9 @@ import java.util.Map; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.data.MongoItemReader; import org.springframework.batch.item.data.MongoItemWriter; import org.springframework.batch.item.data.builder.MongoItemReaderBuilder; @@ -40,15 +41,6 @@ import org.springframework.data.mongodb.core.MongoTemplate; @EnableBatchProcessing public class InsertionJobConfiguration { - private JobBuilderFactory jobBuilderFactory; - - private StepBuilderFactory stepBuilderFactory; - - public InsertionJobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) { - this.jobBuilderFactory = jobBuilderFactory; - this.stepBuilderFactory = stepBuilderFactory; - } - @Bean public MongoItemReader mongoItemReader(MongoTemplate mongoTemplate) { Map sortOptions = new HashMap<>(); @@ -63,14 +55,15 @@ public class InsertionJobConfiguration { } @Bean - public Step step(MongoItemReader mongoItemReader, MongoItemWriter mongoItemWriter) { - return this.stepBuilderFactory.get("step").chunk(2).reader(mongoItemReader) + public Step step(JobRepository jobRepository, MongoItemReader mongoItemReader, + MongoItemWriter mongoItemWriter) { + return new StepBuilder("step").repository(jobRepository).chunk(2).reader(mongoItemReader) .writer(mongoItemWriter).build(); } @Bean - public Job insertionJob(Step step) { - return this.jobBuilderFactory.get("insertionJob").start(step).build(); + public Job insertionJob(JobRepository jobRepository, Step step) { + return new JobBuilder("insertionJob").repository(jobRepository).start(step).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java index fc14eac08..9b59521cb 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java @@ -22,7 +22,8 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.springframework.batch.core.Job; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.batch.integration.chunk.RemoteChunkingManagerStepBuilderFactory; import org.springframework.batch.integration.config.annotation.EnableBatchIntegration; @@ -57,9 +58,6 @@ public class ManagerConfiguration { @Value("${broker.url}") private String brokerUrl; - @Autowired - private JobBuilderFactory jobBuilderFactory; - @Autowired private RemoteChunkingManagerStepBuilderFactory managerStepBuilderFactory; @@ -113,8 +111,8 @@ public class ManagerConfiguration { } @Bean - public Job remoteChunkingJob() { - return this.jobBuilderFactory.get("remoteChunkingJob").start(managerStep()).build(); + public Job remoteChunkingJob(JobRepository jobRepository) { + return new JobBuilder("remoteChunkingJob").repository(jobRepository).start(managerStep()).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java index ff71faffa..29a140bc4 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java @@ -20,7 +20,8 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.integration.config.annotation.EnableBatchIntegration; import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilderFactory; import org.springframework.batch.sample.remotepartitioning.BasicPartitioner; @@ -47,14 +48,10 @@ public class ManagerConfiguration { private static final int GRID_SIZE = 3; - private final JobBuilderFactory jobBuilderFactory; - private final RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory; - public ManagerConfiguration(JobBuilderFactory jobBuilderFactory, - RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) { + public ManagerConfiguration(RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) { - this.jobBuilderFactory = jobBuilderFactory; this.managerStepBuilderFactory = managerStepBuilderFactory; } @@ -96,8 +93,8 @@ public class ManagerConfiguration { } @Bean - public Job remotePartitioningJob() { - return this.jobBuilderFactory.get("remotePartitioningJob").start(managerStep()).build(); + public Job remotePartitioningJob(JobRepository jobRepository) { + return new JobBuilder("remotePartitioningJob").repository(jobRepository).start(managerStep()).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java index 6d35d0ff0..46f522ffe 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java @@ -20,7 +20,8 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.integration.config.annotation.EnableBatchIntegration; import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilderFactory; import org.springframework.batch.sample.remotepartitioning.BasicPartitioner; @@ -47,14 +48,10 @@ public class ManagerConfiguration { private static final int GRID_SIZE = 3; - private final JobBuilderFactory jobBuilderFactory; - private final RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory; - public ManagerConfiguration(JobBuilderFactory jobBuilderFactory, - RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) { + public ManagerConfiguration(RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) { - this.jobBuilderFactory = jobBuilderFactory; this.managerStepBuilderFactory = managerStepBuilderFactory; } @@ -82,8 +79,8 @@ public class ManagerConfiguration { } @Bean - public Job remotePartitioningJob() { - return this.jobBuilderFactory.get("remotePartitioningJob").start(managerStep()).build(); + public Job remotePartitioningJob(JobRepository jobRepository) { + return new JobBuilder("remotePartitioningJob").repository(jobRepository).start(managerStep()).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java index c330b89a7..54d3c1000 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java @@ -21,8 +21,9 @@ import java.util.Arrays; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; @@ -40,16 +41,9 @@ import org.springframework.transaction.PlatformTransactionManager; @Import(DataSourceConfiguration.class) public class SkippableExceptionDuringProcessSample { - private final JobBuilderFactory jobBuilderFactory; - - private final StepBuilderFactory stepBuilderFactory; - private final PlatformTransactionManager transactionManager; - public SkippableExceptionDuringProcessSample(JobBuilderFactory jobBuilderFactory, - StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager) { - this.jobBuilderFactory = jobBuilderFactory; - this.stepBuilderFactory = stepBuilderFactory; + public SkippableExceptionDuringProcessSample(PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; } @@ -88,15 +82,15 @@ public class SkippableExceptionDuringProcessSample { } @Bean - public Step step() { - return this.stepBuilderFactory.get("step").chunk(3) + public Step step(JobRepository jobRepository) { + return new StepBuilder("step").repository(jobRepository).chunk(3) .transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor()) .writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build(); } @Bean - public Job job() { - return this.jobBuilderFactory.get("job").start(step()).build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java index 64220bcd6..f85c4dac2 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java @@ -21,8 +21,9 @@ import java.util.Arrays; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; @@ -40,16 +41,9 @@ import org.springframework.transaction.PlatformTransactionManager; @Import(DataSourceConfiguration.class) public class SkippableExceptionDuringReadSample { - private final JobBuilderFactory jobBuilderFactory; - - private final StepBuilderFactory stepBuilderFactory; - private final PlatformTransactionManager transactionManager; - public SkippableExceptionDuringReadSample(JobBuilderFactory jobBuilderFactory, - StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager) { - this.jobBuilderFactory = jobBuilderFactory; - this.stepBuilderFactory = stepBuilderFactory; + public SkippableExceptionDuringReadSample(PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; } @@ -88,15 +82,15 @@ public class SkippableExceptionDuringReadSample { } @Bean - public Step step() { - return this.stepBuilderFactory.get("step").chunk(3) + public Step step(JobRepository jobRepository) { + return new StepBuilder("step").repository(jobRepository).chunk(3) .transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor()) .writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build(); } @Bean - public Job job() { - return this.jobBuilderFactory.get("job").start(step()).build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java index 3db58e398..6f3c82d66 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java @@ -21,8 +21,9 @@ import java.util.Arrays; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; @@ -40,16 +41,9 @@ import org.springframework.transaction.PlatformTransactionManager; @Import(DataSourceConfiguration.class) public class SkippableExceptionDuringWriteSample { - private final JobBuilderFactory jobBuilderFactory; - - private final StepBuilderFactory stepBuilderFactory; - private final PlatformTransactionManager transactionManager; - public SkippableExceptionDuringWriteSample(JobBuilderFactory jobBuilderFactory, - StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager) { - this.jobBuilderFactory = jobBuilderFactory; - this.stepBuilderFactory = stepBuilderFactory; + public SkippableExceptionDuringWriteSample(PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; } @@ -88,15 +82,15 @@ public class SkippableExceptionDuringWriteSample { } @Bean - public Step step() { - return this.stepBuilderFactory.get("step").chunk(3) + public Step step(JobRepository jobRepository) { + return new StepBuilder("step").repository(jobRepository).chunk(3) .transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor()) .writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build(); } @Bean - public Job job() { - return this.jobBuilderFactory.get("job").start(step()).build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java index d33163668..fd460b408 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java @@ -23,8 +23,9 @@ import javax.sql.DataSource; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +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.batch.item.support.ListItemWriter; import org.springframework.batch.item.validator.BeanValidatingItemProcessor; @@ -42,12 +43,6 @@ import org.springframework.jdbc.support.JdbcTransactionManager; @EnableBatchProcessing public class ValidationSampleConfiguration { - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - @Bean public ListItemReader itemReader() { Person person1 = new Person(1, "foo"); @@ -70,14 +65,15 @@ public class ValidationSampleConfiguration { } @Bean - public Step step() throws Exception { - return this.steps.get("step").chunk(1).transactionManager(transactionManager(dataSource())) - .reader(itemReader()).processor(itemValidator()).writer(itemWriter()).build(); + public Step step(JobRepository jobRepository) throws Exception { + return new StepBuilder("step").repository(jobRepository).chunk(1) + .transactionManager(transactionManager(dataSource())).reader(itemReader()).processor(itemValidator()) + .writer(itemWriter()).build(); } @Bean - public Job job() throws Exception { - return this.jobs.get("job").start(step()).build(); + public Job job(JobRepository jobRepository) throws Exception { + return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build(); } @Bean diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java index a3205bdb3..01efe6a8c 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java @@ -32,9 +32,10 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.item.json.GsonJsonObjectReader; import org.springframework.batch.item.json.JacksonJsonObjectMarshaller; import org.springframework.batch.item.json.JsonItemReader; @@ -73,12 +74,6 @@ class JsonSupportIntegrationTests { @EnableBatchProcessing static class JobConfiguration { - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - @Bean public JsonItemReader itemReader() { return new JsonItemReaderBuilder().name("tradesJsonItemReader") @@ -94,14 +89,15 @@ class JsonSupportIntegrationTests { } @Bean - public Step step() { - return steps.get("step").chunk(2).transactionManager(transactionManager(dataSource())) - .reader(itemReader()).writer(itemWriter()).build(); + public Step step(JobRepository jobRepository) { + return new StepBuilder("step").repository(jobRepository).chunk(2) + .transactionManager(transactionManager(dataSource())).reader(itemReader()).writer(itemWriter()) + .build(); } @Bean - public Job job() { - return jobs.get("job").start(step()).build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build(); } @Bean diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java index 3e37b7de0..ed05c6934 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java @@ -24,9 +24,10 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.scope.context.ChunkContext; +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.beans.factory.annotation.Autowired; @@ -79,15 +80,9 @@ class JobLauncherTestUtilsTests { @EnableBatchProcessing static class TestJobConfiguration { - @Autowired - public JobBuilderFactory jobBuilderFactory; - - @Autowired - public StepBuilderFactory stepBuilderFactory; - @Bean - public Step step() { - return stepBuilderFactory.get("step1").tasklet(new Tasklet() { + public Step step(JobRepository jobRepository) { + return new StepBuilder("step1").repository(jobRepository).tasklet(new Tasklet() { @Nullable @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { @@ -97,14 +92,14 @@ class JobLauncherTestUtilsTests { } @Bean - public Job job() { - return jobBuilderFactory.get("job").flow(step()).end().build(); + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository).flow(step(jobRepository)).end().build(); } @Bean - public JobLauncherTestUtils testUtils() { + public JobLauncherTestUtils testUtils(Job jobUnderTest) { JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); - jobLauncherTestUtils.setJob(job()); + jobLauncherTestUtils.setJob(jobUnderTest); return jobLauncherTestUtils; } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java index 25534fd2b..97c736c30 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java @@ -28,10 +28,11 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.JobScope; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepScope; +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.ItemReader; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.repeat.RepeatStatus; @@ -118,12 +119,6 @@ public class SpringBatchTestJUnit4Tests { @EnableBatchProcessing public static class JobConfiguration { - @Autowired - private JobBuilderFactory jobBuilderFactory; - - @Autowired - private StepBuilderFactory stepBuilderFactory; - @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL) @@ -149,9 +144,9 @@ public class SpringBatchTestJUnit4Tests { } @Bean - public Job job() { - return this.jobBuilderFactory.get("job") - .start(this.stepBuilderFactory.get("step") + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager(dataSource())).build()) .build(); diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java index e9e3ff484..13d019276 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java @@ -29,10 +29,11 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.JobScope; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepScope; +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.ItemReader; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.repeat.RepeatStatus; @@ -143,9 +144,10 @@ public class SpringBatchTestJUnit5Tests { } @Bean - public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) { - return jobBuilderFactory.get("job") - .start(stepBuilderFactory.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) + public Job job(JobRepository jobRepository) { + return new JobBuilder("job").repository(jobRepository) + .start(new StepBuilder("step").repository(jobRepository) + .tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED) .transactionManager(transactionManager(dataSource())).build()) .build(); } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java index 278da2a27..ee8eb8ce5 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java @@ -31,9 +31,10 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.annotation.AfterStep; import org.springframework.batch.core.annotation.BeforeStep; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepScope; +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.Chunk; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; @@ -99,12 +100,6 @@ class StepScopeAnnotatedListenerIntegrationTests { @EnableBatchProcessing static class TestConfig { - @Autowired - private JobBuilderFactory jobBuilder; - - @Autowired - private StepBuilderFactory stepBuilder; - @Autowired private PlatformTransactionManager transactionManager; @@ -127,13 +122,14 @@ class StepScopeAnnotatedListenerIntegrationTests { } @Bean - public Job jobUnderTest() { - return jobBuilder.get("job-under-test").start(stepUnderTest()).build(); + public Job jobUnderTest(JobRepository jobRepository) { + return new JobBuilder("job-under-test").repository(jobRepository).start(stepUnderTest(jobRepository)) + .build(); } @Bean - public Step stepUnderTest() { - return stepBuilder.get("step-under-test").chunk(1) + public Step stepUnderTest(JobRepository jobRepository) { + return new StepBuilder("step-under-test").repository(jobRepository).chunk(1) .transactionManager(this.transactionManager).reader(reader()).processor(processor()) .writer(writer()).build(); }