mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Fix Spring Batch deprecations
See gh-32419
This commit is contained in:
parent
190d4cbc2f
commit
bac7d62476
@ -99,8 +99,7 @@ class JobLauncherApplicationRunnerTests {
|
|||||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||||
Job job = jobLauncherContext.jobBuilder()
|
Job job = jobLauncherContext.jobBuilder()
|
||||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||||
.transactionManager(transactionManager).build())
|
|
||||||
.incrementer(new RunIdIncrementer()).build();
|
.incrementer(new RunIdIncrementer()).build();
|
||||||
jobLauncherContext.runner.execute(job, new JobParameters());
|
jobLauncherContext.runner.execute(job, new JobParameters());
|
||||||
jobLauncherContext.runner.execute(job, new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
jobLauncherContext.runner.execute(job, new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
||||||
@ -113,8 +112,9 @@ class JobLauncherApplicationRunnerTests {
|
|||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> {
|
||||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||||
Job job = jobLauncherContext.jobBuilder().start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
Job job = jobLauncherContext.jobBuilder()
|
||||||
.transactionManager(transactionManager).build()).build();
|
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||||
|
.build();
|
||||||
// start a job instance
|
// start a job instance
|
||||||
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
|
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
|
||||||
jobLauncherContext.runner.execute(job, jobParameters);
|
jobLauncherContext.runner.execute(job, jobParameters);
|
||||||
@ -132,8 +132,7 @@ class JobLauncherApplicationRunnerTests {
|
|||||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||||
Job job = jobLauncherContext.jobBuilder().preventRestart()
|
Job job = jobLauncherContext.jobBuilder().preventRestart()
|
||||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||||
.transactionManager(transactionManager).build())
|
|
||||||
.incrementer(new RunIdIncrementer()).build();
|
.incrementer(new RunIdIncrementer()).build();
|
||||||
jobLauncherContext.runner.execute(job, new JobParameters());
|
jobLauncherContext.runner.execute(job, new JobParameters());
|
||||||
jobLauncherContext.runner.execute(job, new JobParameters());
|
jobLauncherContext.runner.execute(job, new JobParameters());
|
||||||
@ -155,8 +154,7 @@ class JobLauncherApplicationRunnerTests {
|
|||||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||||
Job job = jobLauncherContext.jobBuilder()
|
Job job = jobLauncherContext.jobBuilder()
|
||||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||||
.transactionManager(transactionManager).build())
|
|
||||||
.incrementer(new RunIdIncrementer()).build();
|
.incrementer(new RunIdIncrementer()).build();
|
||||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
||||||
.toJobParameters();
|
.toJobParameters();
|
||||||
@ -193,10 +191,9 @@ class JobLauncherApplicationRunnerTests {
|
|||||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||||
JobRepository jobRepository = context.getBean(JobRepository.class);
|
JobRepository jobRepository = context.getBean(JobRepository.class);
|
||||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||||
this.stepBuilder = new StepBuilder("step").repository(jobRepository);
|
this.stepBuilder = new StepBuilder("step", jobRepository);
|
||||||
this.step = this.stepBuilder.tasklet((contribution, chunkContext) -> null)
|
this.step = this.stepBuilder.tasklet((contribution, chunkContext) -> null, transactionManager).build();
|
||||||
.transactionManager(transactionManager).build();
|
this.jobBuilder = new JobBuilder("job", jobRepository);
|
||||||
this.jobBuilder = new JobBuilder("job").repository(jobRepository);
|
|
||||||
this.job = this.jobBuilder.start(this.step).build();
|
this.job = this.jobBuilder.start(this.step).build();
|
||||||
this.jobExplorer = context.getBean(JobExplorer.class);
|
this.jobExplorer = context.getBean(JobExplorer.class);
|
||||||
this.runner = new JobLauncherApplicationRunner(jobLauncher, this.jobExplorer, jobRepository);
|
this.runner = new JobLauncherApplicationRunner(jobLauncher, this.jobExplorer, jobRepository);
|
||||||
|
@ -40,13 +40,12 @@ public class SampleBatchApplication {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
Job job(JobRepository jobRepository, Step step) {
|
Job job(JobRepository jobRepository, Step step) {
|
||||||
return new JobBuilder("job").repository(jobRepository).start(step).build();
|
return new JobBuilder("job", jobRepository).start(step).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
Step step1(JobRepository jobRepository, Tasklet tasklet, PlatformTransactionManager transactionManager) {
|
Step step1(JobRepository jobRepository, Tasklet tasklet, PlatformTransactionManager transactionManager) {
|
||||||
return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet)
|
return new StepBuilder("step1", jobRepository).tasklet(tasklet, transactionManager).build();
|
||||||
.transactionManager(transactionManager).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user