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 4d75da6acb..6bcf4c108d 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 @@
*/
@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 JobRegistry jobRegistry() throws Exception {
*/
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 840c530021..16b1c9ec76 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 @@
* 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 @@
*
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 ed57682325..92965da775 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 @@
*
* @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 ea56a6ee8e..e7f76ba866 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 @@
*
* @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 20d526216e..e1517683fe 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.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 @@ void testInlineDataSourceDefinition() throws Exception {
@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 97e5396897..fcb65ea298 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.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 @@ private void testJob(String jobName, BatchStatus status, int stepExecutionCount,
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 RepeatStatus execute(StepContribution contribution, ChunkContext context)
@Import(DataSourceConfiguration.class)
public static class AnotherConfiguration {
- @Autowired
- private JobBuilderFactory jobs;
-
- @Autowired
- private StepBuilderFactory steps;
-
@Autowired
private JdbcTransactionManager transactionManager;
@@ -168,14 +165,15 @@ public static class AnotherConfiguration {
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 @@ protected Step step3() throws Exception {
@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 @@ protected void doExecute(StepExecution stepExecution) throws Exception {
@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 864cc08897..88709114a4 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.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 @@ public ApplicationObjectSupport fakeApplicationObjectSupport() {
};
}
- @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 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext context)
@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 42acc89afe..048b791831 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.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.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 @@ public JobExplorerFactoryBean jobExplorerFactoryBean() {
}
@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 @@ public DataSourceInitializer dataSourceInitializer() {
}
@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 800dca4d74..3787c6be3e 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.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.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 @@ static class JobConfiguration {
@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 7b5a3f19ed..bc8e60d515 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.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 @@ void testListeners() throws Exception {
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 666352d8e2..b9d76c39e5 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.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 @@ void testOnProcessError() throws Exception {
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 09c6ae22a4..b63e157d4b 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.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 @@ void testBatchMetrics() throws Exception {
@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 @@ public Step step3() {
}
@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 2bd23d2139..cafa55b5b3 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.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 @@ private void bootstrap(Class> configurationClass) {
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 @@ public void write(Chunk extends String> chunk) throws Exception {
};
}
- public abstract Step step();
+ public abstract Step step(JobRepository jobRepository);
}
@@ -209,8 +203,8 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
@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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
@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 0e76e67165..f5e2a701a0 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.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 @@ void testConcurrentLongRunningJobExecutions() throws Exception {
@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 @@ public TaskExecutor taskExecutor() {
}
@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 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
}
@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 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
}
@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 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
}
@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 53894fbcf6..59f3c33d16 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 ec505b1b67..2e7c3419b8 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 de54ec2736..402dd0cc4e 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 7281108cf6..4220842ca5 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 888f9f36f3..cbfd8d9545 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.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 @@ public DataSource dataSource() throws Exception {
}
@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 d65085fab4..987ea321f8 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 6eba4326d3..979483e8e2 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 2f19a4cc7b..5a210b31d4 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 70376d6136..d3ee2cfb69 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.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 @@ public DataSource dataSource() throws Exception {
}
@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 7ea53c9e16..cb7f427a15 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 26387f6e84..a3cf585f9b 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 05a76fe17a..7662c0e993 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.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 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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 a0879a7f69..c462228615 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.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 @@ public DataSource dataSource() throws Exception {
}
@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 4eb34611e4..59231241db 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.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 @@ void setUp() {
}
};
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 @@ public void write(Chunk extends Integer> items) throws Exception {
}
};
- 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 @@ public void write(Chunk extends Integer> chunk) throws Exception {
}
};
- 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 eb38f8a105..d721c1eb31 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 @@
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 @@
@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 129e66070d..7bdc605d5f 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 Step step1() {
}
@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 bf6865b827..330aedd0d2 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 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 6528ecad95..d88e90a9b3 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 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 @@
@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 MongoItemWriter mongoPersonRemover(MongoTemplate mongoTemplate) {
}
@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 ae9c56e9da..5dc07dd7c2 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 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 @@
@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 MongoItemWriter mongoItemWriter(MongoTemplate mongoTemplate) {
}
@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 fc14eac080..9b59521cb1 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.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 TaskletStep managerStep() {
}
@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 ff71faffa9..29a140bc4d 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.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 Step managerStep() {
}
@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 6d35d0ff0f..46f522ffe5 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.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 Step managerStep() {
}
@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 c330b89a7b..54d3c10003 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 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(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 ItemWriter itemWriter() {
}
@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 64220bcd67..f85c4dac23 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 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(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 ItemWriter itemWriter() {
}
@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 3db58e3982..6f3c82d664 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 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(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 ItemWriter itemWriter() {
}
@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 d331636683..fd460b4081 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 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 @@
@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 BeanValidatingItemProcessor itemValidator() throws Exception {
}
@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 a3205bdb3c..01efe6a8cd 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.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 @@ void setUp() throws Exception {
@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 @@ public JsonFileItemWriter itemWriter() {
}
@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 3e37b7de0b..ed05c69342 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.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 @@ void getUniqueJobParameters_doesNotRepeatJobParameters() {
@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 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
}
@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 25534fd2b8..97c736c30b 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.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 void testJob() throws Exception {
@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 ItemReader jobScopedItemReader(@Value("#{jobExecutionContext['inp
}
@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 e9e3ff484a..13d0192768 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.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 ItemReader jobScopedItemReader(@Value("#{jobExecutionContext['inp
}
@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 278da2a27f..ee8eb8ce50 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.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 @@ public String read() throws Exception {
@EnableBatchProcessing
static class TestConfig {
- @Autowired
- private JobBuilderFactory jobBuilder;
-
- @Autowired
- private StepBuilderFactory stepBuilder;
-
@Autowired
private PlatformTransactionManager transactionManager;
@@ -127,13 +122,14 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
}
@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();
}