Improve Step/Job builder APIs to guide users to set mandatory properties
Before this commit, the user had to manually set the job repository and transaction manager on `JobBuilder` and `StepBuilder` instances with a chained call to `.repository(jobRepository)` and `.transactionManager(transactionManager)`. This is error prone and can lead to runtime errors if these properties are not set. This commit introduces new APIs to guide the user to set these properties at builder creation time. Resolves #4192
This commit is contained in:
@@ -82,18 +82,18 @@ class JobLauncherTestUtilsTests {
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet(new Tasklet() {
|
||||
return new StepBuilder("step1", jobRepository).tasklet(new Tasklet() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
return null;
|
||||
}
|
||||
}).transactionManager(transactionManager(dataSource())).build();
|
||||
}, transactionManager(dataSource())).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).flow(step(jobRepository)).end().build();
|
||||
return new JobBuilder("job", jobRepository).flow(step(jobRepository)).end().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -145,11 +145,9 @@ public class SpringBatchTestJUnit4Tests {
|
||||
|
||||
@Bean
|
||||
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();
|
||||
return new JobBuilder("job", jobRepository).start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager(dataSource()))
|
||||
.build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -145,11 +145,9 @@ public class SpringBatchTestJUnit5Tests {
|
||||
|
||||
@Bean
|
||||
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();
|
||||
return new JobBuilder("job", jobRepository).start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager(dataSource()))
|
||||
.build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -123,15 +123,13 @@ class StepScopeAnnotatedListenerIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job jobUnderTest(JobRepository jobRepository) {
|
||||
return new JobBuilder("job-under-test").repository(jobRepository).start(stepUnderTest(jobRepository))
|
||||
.build();
|
||||
return new JobBuilder("job-under-test", jobRepository).start(stepUnderTest(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step stepUnderTest(JobRepository jobRepository) {
|
||||
return new StepBuilder("step-under-test").repository(jobRepository).<String, String>chunk(1)
|
||||
.transactionManager(this.transactionManager).reader(reader()).processor(processor())
|
||||
.writer(writer()).build();
|
||||
return new StepBuilder("step-under-test", jobRepository).<String, String>chunk(1, this.transactionManager)
|
||||
.reader(reader()).processor(processor()).writer(writer()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user