Adapt to recent deprecations in Spring Batch
See gh-32237
This commit is contained in:
@@ -30,8 +30,6 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
|
||||
@@ -183,23 +181,23 @@ class JobLauncherApplicationRunnerTests {
|
||||
|
||||
private final JobExplorer jobExplorer;
|
||||
|
||||
private final JobBuilderFactory jobs;
|
||||
|
||||
private final StepBuilderFactory steps;
|
||||
private final JobBuilder jobBuilder;
|
||||
|
||||
private final Job job;
|
||||
|
||||
private final StepBuilder stepBuilder;
|
||||
|
||||
private final Step step;
|
||||
|
||||
JobLauncherApplicationRunnerContext(ApplicationContext context) {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
JobRepository jobRepository = context.getBean(JobRepository.class);
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
this.jobs = new JobBuilderFactory(jobRepository);
|
||||
this.steps = new StepBuilderFactory(jobRepository);
|
||||
this.step = this.steps.get("step").tasklet((contribution, chunkContext) -> null)
|
||||
this.stepBuilder = new StepBuilder("step").repository(jobRepository);
|
||||
this.step = this.stepBuilder.tasklet((contribution, chunkContext) -> null)
|
||||
.transactionManager(transactionManager).build();
|
||||
this.job = this.jobs.get("job").start(this.step).build();
|
||||
this.jobBuilder = new JobBuilder("job").repository(jobRepository);
|
||||
this.job = this.jobBuilder.start(this.step).build();
|
||||
this.jobExplorer = context.getBean(JobExplorer.class);
|
||||
this.runner = new JobLauncherApplicationRunner(jobLauncher, this.jobExplorer, jobRepository);
|
||||
}
|
||||
@@ -213,15 +211,15 @@ class JobLauncherApplicationRunnerTests {
|
||||
}
|
||||
|
||||
JobBuilder jobBuilder() {
|
||||
return this.jobs.get("job");
|
||||
return this.jobBuilder;
|
||||
}
|
||||
|
||||
StepBuilder stepBuilder() {
|
||||
return this.steps.get("step");
|
||||
return this.stepBuilder;
|
||||
}
|
||||
|
||||
SimpleJobBuilder configureJob() {
|
||||
return this.jobs.get("job").start(this.step);
|
||||
return this.jobBuilder.start(this.step);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ package smoketest.batch;
|
||||
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.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -32,32 +33,20 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
@EnableBatchProcessing
|
||||
public class SampleBatchApplication {
|
||||
|
||||
private JobBuilderFactory jobs;
|
||||
|
||||
private StepBuilderFactory steps;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
public SampleBatchApplication(JobBuilderFactory jobs, StepBuilderFactory steps,
|
||||
PlatformTransactionManager transactionManager) {
|
||||
this.jobs = jobs;
|
||||
this.steps = steps;
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Tasklet tasklet() {
|
||||
Tasklet tasklet() {
|
||||
return (contribution, context) -> RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobs.get("job").start(step1()).build();
|
||||
Job job(JobRepository jobRepository, Step step) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step1() {
|
||||
return this.steps.get("step1").tasklet(tasklet()).transactionManager(this.transactionManager).build();
|
||||
Step step1(JobRepository jobRepository, Tasklet tasklet, PlatformTransactionManager transactionManager) {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet)
|
||||
.transactionManager(transactionManager).build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user