Skip to content

Fix Spring Batch deprecations #32419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ void retryFailedExecution() {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
Job job = jobLauncherContext.jobBuilder()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
.transactionManager(transactionManager).build())
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.incrementer(new RunIdIncrementer()).build();
jobLauncherContext.runner.execute(job, new JobParameters());
jobLauncherContext.runner.execute(job, new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
Expand All @@ -113,8 +112,9 @@ void runDifferentInstances() {
this.contextRunner.run((context) -> {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
Job job = jobLauncherContext.jobBuilder().start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
.transactionManager(transactionManager).build()).build();
Job job = jobLauncherContext.jobBuilder()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.build();
// start a job instance
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
jobLauncherContext.runner.execute(job, jobParameters);
Expand All @@ -132,8 +132,7 @@ void retryFailedExecutionOnNonRestartableJob() {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
Job job = jobLauncherContext.jobBuilder().preventRestart()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
.transactionManager(transactionManager).build())
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.incrementer(new RunIdIncrementer()).build();
jobLauncherContext.runner.execute(job, new JobParameters());
jobLauncherContext.runner.execute(job, new JobParameters());
Expand All @@ -155,8 +154,7 @@ void retryFailedExecutionWithNonIdentifyingParameters() {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
Job job = jobLauncherContext.jobBuilder()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
.transactionManager(transactionManager).build())
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.incrementer(new RunIdIncrementer()).build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
.toJobParameters();
Expand Down Expand Up @@ -193,10 +191,9 @@ static class JobLauncherApplicationRunnerContext {
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
JobRepository jobRepository = context.getBean(JobRepository.class);
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
this.stepBuilder = new StepBuilder("step").repository(jobRepository);
this.step = this.stepBuilder.tasklet((contribution, chunkContext) -> null)
.transactionManager(transactionManager).build();
this.jobBuilder = new JobBuilder("job").repository(jobRepository);
this.stepBuilder = new StepBuilder("step", jobRepository);
this.step = this.stepBuilder.tasklet((contribution, chunkContext) -> null, transactionManager).build();
this.jobBuilder = new JobBuilder("job", jobRepository);
this.job = this.jobBuilder.start(this.step).build();
this.jobExplorer = context.getBean(JobExplorer.class);
this.runner = new JobLauncherApplicationRunner(jobLauncher, this.jobExplorer, jobRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ Tasklet tasklet() {

@Bean
Job job(JobRepository jobRepository, Step step) {
return new JobBuilder("job").repository(jobRepository).start(step).build();
return new JobBuilder("job", jobRepository).start(step).build();
}

@Bean
Step step1(JobRepository jobRepository, Tasklet tasklet, PlatformTransactionManager transactionManager) {
return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet)
.transactionManager(transactionManager).build();
return new StepBuilder("step1", jobRepository).tasklet(tasklet, transactionManager).build();
}

public static void main(String[] args) {
Expand Down