Skip to content

Commit ba539db

Browse files
committed
Remove usage of deprecated APIs
1 parent ecd0b8b commit ba539db

File tree

93 files changed

+423
-786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+423
-786
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/SpringBatchVersionTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525
import org.springframework.batch.core.job.parameters.JobParameters;
2626
import org.springframework.batch.core.job.parameters.JobParametersBuilder;
2727
import org.springframework.batch.core.job.builder.JobBuilder;
28-
import org.springframework.batch.core.launch.JobLauncher;
28+
import org.springframework.batch.core.launch.JobOperator;
2929
import org.springframework.batch.core.repository.JobRepository;
3030
import org.springframework.batch.core.step.builder.StepBuilder;
3131
import org.springframework.batch.repeat.RepeatStatus;
@@ -51,7 +51,7 @@
5151
public class SpringBatchVersionTests {
5252

5353
@Autowired
54-
private JobLauncher jobLauncher;
54+
private JobOperator jobOperator;
5555

5656
@Autowired
5757
private Job job;
@@ -62,7 +62,7 @@ void testBatchVersionInExecutionContext() throws Exception {
6262
JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
6363

6464
// when
65-
JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters);
65+
JobExecution jobExecution = this.jobOperator.start(this.job, jobParameters);
6666

6767
// then
6868
assertNotNull(jobExecution);

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/BatchRegistrarTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.batch.core.converter.JobParametersConverter;
3232
import org.springframework.batch.core.converter.JsonJobParametersConverter;
3333
import org.springframework.batch.core.job.parameters.JobParameters;
34-
import org.springframework.batch.core.launch.JobLauncher;
3534
import org.springframework.batch.core.launch.JobOperator;
3635
import org.springframework.batch.core.repository.JobRepository;
3736
import org.springframework.batch.core.repository.dao.jdbc.JdbcExecutionContextDao;
@@ -141,13 +140,11 @@ void testDefaultInfrastructureBeansRegistration() {
141140
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(JobConfiguration.class);
142141

143142
// when
144-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
145143
JobRepository jobRepository = context.getBean(JobRepository.class);
146144
JobRegistry jobRegistry = context.getBean(JobRegistry.class);
147145
JobOperator jobOperator = context.getBean(JobOperator.class);
148146

149147
// then
150-
Assertions.assertNotNull(jobLauncher);
151148
Assertions.assertNotNull(jobRepository);
152149
Assertions.assertNotNull(jobRegistry);
153150
Assertions.assertNotNull(jobOperator);
@@ -216,11 +213,6 @@ public JobRepository jobRepository() {
216213
return Mockito.mock();
217214
}
218215

219-
@Bean
220-
public JobLauncher jobLauncher() {
221-
return Mockito.mock();
222-
}
223-
224216
@Bean
225217
public JobRegistry jobRegistry() {
226218
return Mockito.mock();

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 the original author or authors.
2+
* Copyright 2022-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525
import org.springframework.batch.core.job.JobExecution;
2626
import org.springframework.batch.core.job.parameters.JobParameters;
2727
import org.springframework.batch.core.job.builder.JobBuilder;
28-
import org.springframework.batch.core.launch.JobLauncher;
28+
import org.springframework.batch.core.launch.JobOperator;
2929
import org.springframework.batch.core.repository.JobRepository;
3030
import org.springframework.batch.core.step.builder.StepBuilder;
3131
import org.springframework.batch.repeat.RepeatStatus;
@@ -49,8 +49,8 @@ class InlineDataSourceDefinitionTests {
4949
void testInlineDataSourceDefinition() throws Exception {
5050
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MyJobConfiguration.class);
5151
Job job = applicationContext.getBean(Job.class);
52-
JobLauncher jobLauncher = applicationContext.getBean(JobLauncher.class);
53-
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
52+
JobOperator jobOperator = applicationContext.getBean(JobOperator.class);
53+
JobExecution jobExecution = jobOperator.start(job, new JobParameters());
5454
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
5555
}
5656

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import org.springframework.batch.core.step.StepContribution;
2929
import org.springframework.batch.core.job.builder.JobBuilder;
3030
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
31-
import org.springframework.batch.core.launch.JobLauncher;
31+
import org.springframework.batch.core.launch.JobOperator;
3232
import org.springframework.batch.core.repository.JobRepository;
3333
import org.springframework.batch.core.scope.context.ChunkContext;
3434
import org.springframework.batch.core.step.builder.StepBuilder;
@@ -86,8 +86,8 @@ private void testJob(String jobName, BatchStatus status, int stepExecutionCount,
8686
configs[0] = DataSourceConfiguration.class;
8787
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
8888
Job job = jobName == null ? context.getBean(Job.class) : context.getBean(jobName, Job.class);
89-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
90-
JobExecution execution = jobLauncher.run(job,
89+
JobOperator jobOperator = context.getBean(JobOperator.class);
90+
JobExecution execution = jobOperator.start(job,
9191
new JobParametersBuilder().addLong("run.id", (long) (Math.random() * Long.MAX_VALUE))
9292
.toJobParameters());
9393
assertEquals(status, execution.getStatus());

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.springframework.batch.core.repository.explore.JobExplorer;
3535
import org.springframework.batch.core.job.builder.JobBuilder;
3636
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
37-
import org.springframework.batch.core.launch.JobLauncher;
37+
import org.springframework.batch.core.launch.JobOperator;
3838
import org.springframework.batch.core.repository.JobRepository;
3939
import org.springframework.batch.core.scope.context.ChunkContext;
4040
import org.springframework.batch.core.step.builder.StepBuilder;
@@ -72,8 +72,8 @@ private void testJob(String jobName, BatchStatus status, int stepExecutionCount,
7272
configs[0] = DataSourceConfiguration.class;
7373
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
7474
Job job = jobName == null ? context.getBean(Job.class) : context.getBean(JobRegistry.class).getJob(jobName);
75-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
76-
JobExecution execution = jobLauncher.run(job,
75+
JobOperator jobOperator = context.getBean(JobOperator.class);
76+
JobExecution execution = jobOperator.start(job,
7777
new JobParametersBuilder().addLong("run.id", (long) (Math.random() * Long.MAX_VALUE))
7878
.toJobParameters());
7979
assertEquals(status, execution.getStatus());

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/DefaultBatchConfigurationTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.springframework.batch.core.configuration.JobRegistry;
3131
import org.springframework.batch.core.configuration.xml.DummyJobRepository;
3232
import org.springframework.batch.core.job.builder.JobBuilder;
33-
import org.springframework.batch.core.launch.JobLauncher;
3433
import org.springframework.batch.core.launch.JobOperator;
3534
import org.springframework.batch.core.repository.JobRepository;
3635
import org.springframework.batch.core.step.builder.StepBuilder;
@@ -54,10 +53,10 @@ void testDefaultConfiguration() throws Exception {
5453
// given
5554
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyJobConfiguration.class);
5655
Job job = context.getBean(Job.class);
57-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
56+
JobOperator jobOperator = context.getBean(JobOperator.class);
5857

5958
// when
60-
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
59+
JobExecution jobExecution = jobOperator.start(job, new JobParameters());
6160

6261
// then
6362
Assertions.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
@@ -79,13 +78,11 @@ void testDefaultInfrastructureBeansRegistration() {
7978
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyJobConfiguration.class);
8079

8180
// when
82-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
8381
JobRepository jobRepository = context.getBean(JobRepository.class);
8482
JobRegistry jobRegistry = context.getBean(JobRegistry.class);
8583
JobOperator jobOperator = context.getBean(JobOperator.class);
8684

8785
// then
88-
Assertions.assertNotNull(jobLauncher);
8986
Assertions.assertNotNull(jobRepository);
9087
Assertions.assertNotNull(jobRegistry);
9188
Assertions.assertNotNull(jobOperator);

spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2023 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@
4444
import org.springframework.batch.core.job.flow.support.StateTransition;
4545
import org.springframework.batch.core.job.flow.support.state.EndState;
4646
import org.springframework.batch.core.job.flow.support.state.StepState;
47-
import org.springframework.batch.core.launch.JobLauncher;
47+
import org.springframework.batch.core.launch.JobOperator;
4848
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
4949
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
5050
import org.springframework.batch.core.repository.JobRepository;
@@ -150,7 +150,7 @@ public Job job(JobRepository jobRepository) {
150150
private FlowStep flowStep;
151151

152152
@Autowired
153-
private JobLauncher jobLauncher;
153+
private JobOperator jobOperator;
154154

155155
@Autowired
156156
private Job job;
@@ -174,7 +174,7 @@ void testGetStepExecution() throws JobExecutionAlreadyRunningException, JobResta
174174

175175
@Test
176176
void getLastJobExecutionShouldFetchStepExecutions() throws Exception {
177-
this.jobLauncher.run(this.job, new JobParameters());
177+
this.jobOperator.start(this.job, new JobParameters());
178178
JobInstance lastJobInstance = this.jobExplorer.getLastJobInstance("job");
179179
JobExecution lastJobExecution = this.jobExplorer.getLastJobExecution(lastJobInstance);
180180
assertEquals(1, lastJobExecution.getStepExecutions().size());
@@ -224,7 +224,7 @@ public JdbcTransactionManager transactionManager(DataSource dataSource) {
224224
void retrievedJobExecutionsShouldHaveTheirOwnParameters() throws Exception {
225225
// given
226226
ApplicationContext context = new AnnotationConfigApplicationContext(JobConfiguration.class);
227-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
227+
JobOperator jobOperator = context.getBean(JobOperator.class);
228228
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
229229
Job job = context.getBean(Job.class);
230230
long id = 1L;
@@ -236,8 +236,8 @@ void retrievedJobExecutionsShouldHaveTheirOwnParameters() throws Exception {
236236
.toJobParameters();
237237

238238
// when
239-
JobExecution jobExecution1 = jobLauncher.run(job, jobParameters1);
240-
JobExecution jobExecution2 = jobLauncher.run(job, jobParameters2);
239+
JobExecution jobExecution1 = jobOperator.start(job, jobParameters1);
240+
JobExecution jobExecution2 = jobOperator.start(job, jobParameters2);
241241

242242
// then
243243
Assertions.assertEquals(jobExecution1.getJobInstance(), jobExecution2.getJobInstance());

spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import org.springframework.batch.core.listener.JobExecutionListener;
4141
import org.springframework.batch.core.step.Step;
4242
import org.springframework.batch.core.step.StepExecution;
43-
import org.springframework.batch.core.repository.explore.JobExplorer;
44-
import org.springframework.batch.core.repository.explore.support.JobExplorerFactoryBean;
4543
import org.springframework.batch.core.observability.BatchJobObservation;
4644
import org.springframework.batch.core.repository.JobRepository;
4745
import org.springframework.batch.core.repository.support.JdbcJobRepositoryFactoryBean;
@@ -71,8 +69,6 @@ class SimpleJobTests {
7169

7270
private JobRepository jobRepository;
7371

74-
private JobExplorer jobExplorer;
75-
7672
private final List<Serializable> list = new ArrayList<>();
7773

7874
private JobInstance jobInstance;
@@ -91,7 +87,6 @@ class SimpleJobTests {
9187

9288
private SimpleJob job;
9389

94-
@SuppressWarnings("removal")
9590
@BeforeEach
9691
void setUp() throws Exception {
9792
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
@@ -105,11 +100,6 @@ void setUp() throws Exception {
105100
repositoryFactoryBean.setTransactionManager(transactionManager);
106101
repositoryFactoryBean.afterPropertiesSet();
107102
this.jobRepository = repositoryFactoryBean.getObject();
108-
JobExplorerFactoryBean explorerFactoryBean = new JobExplorerFactoryBean();
109-
explorerFactoryBean.setDataSource(embeddedDatabase);
110-
explorerFactoryBean.setTransactionManager(transactionManager);
111-
explorerFactoryBean.afterPropertiesSet();
112-
this.jobExplorer = explorerFactoryBean.getObject();
113103
job = new SimpleJob();
114104
job.setJobRepository(jobRepository);
115105

@@ -487,7 +477,7 @@ void testGetMultipleJobParameters() throws Exception {
487477
JobExecution jobexecution = jobRepository.createJobExecution(job.getName(), firstJobParameters);
488478
job.execute(jobexecution);
489479

490-
List<JobExecution> jobExecutionList = jobExplorer.getJobExecutions(jobexecution.getJobInstance());
480+
List<JobExecution> jobExecutionList = jobRepository.getJobExecutions(jobexecution.getJobInstance());
491481

492482
assertEquals(1, jobExecutionList.size());
493483
assertEquals("first", jobExecutionList.get(0).getJobParameters().getString("JobExecutionParameter"));
@@ -498,7 +488,7 @@ void testGetMultipleJobParameters() throws Exception {
498488
jobexecution = jobRepository.createJobExecution(job.getName(), secondJobParameters);
499489
job.execute(jobexecution);
500490

501-
jobExecutionList = jobExplorer.getJobExecutions(jobexecution.getJobInstance());
491+
jobExecutionList = jobRepository.getJobExecutions(jobexecution.getJobInstance());
502492

503493
assertEquals(2, jobExecutionList.size());
504494
assertEquals("second", jobExecutionList.get(0).getJobParameters().getString("JobExecutionParameter"));
@@ -512,7 +502,7 @@ void testGetMultipleJobParameters() throws Exception {
512502
private void checkRepository(BatchStatus status, ExitStatus exitStatus) {
513503
assertEquals(jobInstance,
514504
this.jobRepository.getLastJobExecution(job.getName(), jobParameters).getJobInstance());
515-
JobExecution jobExecution = this.jobExplorer.getJobExecutions(jobInstance).get(0);
505+
JobExecution jobExecution = this.jobRepository.getJobExecutions(jobInstance).get(0);
516506
assertEquals(jobInstance.getId(), jobExecution.getJobId());
517507
assertEquals(status, jobExecution.getStatus());
518508
if (exitStatus != null) {

spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@
4242
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
4343
import org.springframework.batch.core.job.flow.JobExecutionDecider;
4444
import org.springframework.batch.core.job.flow.support.SimpleFlow;
45-
import org.springframework.batch.core.launch.JobLauncher;
45+
import org.springframework.batch.core.launch.JobOperator;
4646
import org.springframework.batch.core.repository.JobRepository;
4747
import org.springframework.batch.core.repository.support.JdbcJobRepositoryFactoryBean;
4848
import org.springframework.batch.core.step.StepSupport;
@@ -377,12 +377,12 @@ void testBuildWithStopAndRestart() throws Exception {
377377
void testBuildWithJobScopedStep() throws Exception {
378378
// given
379379
ApplicationContext context = new AnnotationConfigApplicationContext(JobConfiguration.class);
380-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
380+
JobOperator jobOperator = context.getBean(JobOperator.class);
381381
Job job = context.getBean(Job.class);
382382
JobParameters jobParameters = new JobParametersBuilder().addLong("chunkSize", 2L).toJobParameters();
383383

384384
// when
385-
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
385+
JobExecution jobExecution = jobOperator.start(job, jobParameters);
386386

387387
// then
388388
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());

spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.batch.core.annotation.AfterJob;
2828
import org.springframework.batch.core.annotation.BeforeJob;
2929
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
30-
import org.springframework.batch.core.launch.JobLauncher;
30+
import org.springframework.batch.core.launch.JobOperator;
3131
import org.springframework.batch.core.repository.JobRepository;
3232
import org.springframework.batch.core.step.builder.StepBuilder;
3333
import org.springframework.batch.repeat.RepeatStatus;
@@ -50,11 +50,11 @@ class JobBuilderTests {
5050
void testListeners() throws Exception {
5151
// given
5252
ApplicationContext context = new AnnotationConfigApplicationContext(MyJobConfiguration.class);
53-
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
53+
JobOperator jobOperator = context.getBean(JobOperator.class);
5454
Job job = context.getBean(Job.class);
5555

5656
// when
57-
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
57+
JobExecution jobExecution = jobOperator.start(job, new JobParameters());
5858

5959
// then
6060
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());

0 commit comments

Comments
 (0)