Skip to content

Commit 02b4422

Browse files
committed
Updated project to use Spring Boot 3.0
Resolves issues: TASK-810 TASK-812 TASK-813
1 parent a95b420 commit 02b4422

File tree

30 files changed

+184
-143
lines changed

30 files changed

+184
-143
lines changed

pom.xml

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.cloud</groupId>
77
<artifactId>spring-cloud-build</artifactId>
8-
<version>3.1.1-SNAPSHOT</version>
8+
<version>4.0.0-SNAPSHOT</version>
99
<relativePath />
1010
</parent>
1111

@@ -84,31 +84,6 @@
8484
<artifactId>spring-cloud-stream</artifactId>
8585
<version>${spring-cloud-stream.version}</version>
8686
</dependency>
87-
<dependency>
88-
<groupId>org.springframework</groupId>
89-
<artifactId>spring-jdbc</artifactId>
90-
<version>5.3.15-SNAPSHOT</version>
91-
</dependency>
92-
<dependency>
93-
<groupId>org.springframework.batch</groupId>
94-
<artifactId>spring-batch-core</artifactId>
95-
<version>${spring-batch.version}</version>
96-
</dependency>
97-
<dependency>
98-
<groupId>org.springframework.batch</groupId>
99-
<artifactId>spring-batch-infrastructure</artifactId>
100-
<version>${spring-batch.version}</version>
101-
</dependency>
102-
<dependency>
103-
<groupId>org.springframework.batch</groupId>
104-
<artifactId>spring-batch-integration</artifactId>
105-
<version>${spring-batch.version}</version>
106-
</dependency>
107-
<dependency>
108-
<groupId>org.springframework.batch</groupId>
109-
<artifactId>spring-batch-test</artifactId>
110-
<version>${spring-batch.version}</version>
111-
</dependency>
11287
</dependencies>
11388
</dependencyManagement>
11489

@@ -125,15 +100,15 @@
125100
</modules>
126101

127102
<properties>
128-
<spring-batch.version>4.3.5-SNAPSHOT</spring-batch.version>
129-
<spring-cloud-stream.version>3.2.1</spring-cloud-stream.version>
103+
104+
<spring-cloud-stream.version>4.0.0-SNAPSHOT</spring-cloud-stream.version>
130105
<spring-cloud-deployer.version>2.7.0</spring-cloud-deployer.version>
131106
<spring-cloud-deployer-local.version>2.7.0
132107
</spring-cloud-deployer-local.version>
133108
<spring-cloud-stream-binder-rabbit.version>${spring-cloud-stream.version}
134109
</spring-cloud-stream-binder-rabbit.version>
135110
<commons-logging.version>1.1</commons-logging.version>
136-
<java-ee-api.version>8.0</java-ee-api.version>
111+
<jakarta-ee-api.version>9.1.0</jakarta-ee-api.version>
137112

138113
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
139114
<sonar.jacoco.reportPath>
@@ -144,6 +119,7 @@
144119
</maven-checkstyle-plugin.failsOnViolation>
145120
<maven-checkstyle-plugin.includeTestSourceDirectory>true
146121
</maven-checkstyle-plugin.includeTestSourceDirectory>
122+
<java.version>17</java.version>
147123
</properties>
148124

149125
<build>
@@ -170,10 +146,10 @@
170146
<groupId>org.apache.maven.plugins</groupId>
171147
<artifactId>maven-compiler-plugin</artifactId>
172148
<configuration>
173-
<source>1.8</source>
174-
<target>1.8</target>
175-
<testSource>1.8</testSource>
176-
<testTarget>1.8</testTarget>
149+
<source>17</source>
150+
<target>17</target>
151+
<testSource>17</testSource>
152+
<testTarget>17</testTarget>
177153
</configuration>
178154
</plugin>
179155
<plugin>
@@ -256,7 +232,7 @@
256232
</configuration>
257233
</execution>
258234
</executions>
259-
<version>0.8.6</version>
235+
<version>0.8.7</version>
260236
</plugin>
261237
<plugin>
262238
<groupId>org.apache.maven.plugins</groupId>

spring-cloud-task-batch/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@
9292
<artifactId>junit-jupiter</artifactId>
9393
<scope>test</scope>
9494
</dependency>
95-
</dependencies>
95+
</dependencies>
9696
</project>

spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2022 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.
@@ -154,22 +154,7 @@ public class DeployerPartitionHandler
154154
* @param jobExplorer used to acquire the status of the job.
155155
* @param resource the url to the app to be launched.
156156
* @param stepName the name of the step.
157-
* @deprecated Use the constructor that accepts {@link TaskRepository} as well as the
158-
* this constructor's set of parameters.
159157
*/
160-
@Deprecated
161-
public DeployerPartitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer,
162-
Resource resource, String stepName) {
163-
Assert.notNull(taskLauncher, "A taskLauncher is required");
164-
Assert.notNull(jobExplorer, "A jobExplorer is required");
165-
Assert.notNull(resource, "A resource is required");
166-
Assert.hasText(stepName, "A step name is required");
167-
168-
this.taskLauncher = taskLauncher;
169-
this.jobExplorer = jobExplorer;
170-
this.resource = resource;
171-
this.stepName = stepName;
172-
}
173158

174159
public DeployerPartitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer,
175160
Resource resource, String stepName, TaskRepository taskRepository) {

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherApplicationRunnerCoreTests.java

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2019 the original author or authors.
2+
* Copyright 2018-2022 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.
@@ -16,6 +16,10 @@
1616

1717
package org.springframework.cloud.task.batch.handler;
1818

19+
import java.util.List;
20+
21+
import javax.sql.DataSource;
22+
1923
import org.junit.jupiter.api.BeforeEach;
2024
import org.junit.jupiter.api.Test;
2125
import org.junit.jupiter.api.extension.ExtendWith;
@@ -32,21 +36,28 @@
3236
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
3337
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
3438
import org.springframework.batch.core.explore.JobExplorer;
35-
import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean;
39+
import org.springframework.batch.core.explore.support.JobExplorerFactoryBean;
3640
import org.springframework.batch.core.launch.JobLauncher;
3741
import org.springframework.batch.core.launch.support.RunIdIncrementer;
3842
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
3943
import org.springframework.batch.core.repository.JobRepository;
4044
import org.springframework.batch.core.repository.JobRestartException;
41-
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
45+
import org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer;
46+
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
4247
import org.springframework.batch.core.step.tasklet.Tasklet;
4348
import org.springframework.batch.repeat.RepeatStatus;
4449
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
4550
import org.springframework.beans.factory.annotation.Autowired;
51+
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
4652
import org.springframework.cloud.task.batch.configuration.TaskBatchProperties;
4753
import org.springframework.cloud.task.listener.TaskException;
4854
import org.springframework.context.annotation.Configuration;
55+
import org.springframework.context.annotation.Import;
56+
import org.springframework.core.io.ClassPathResource;
4957
import org.springframework.core.task.SyncTaskExecutor;
58+
import org.springframework.jdbc.core.JdbcTemplate;
59+
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
60+
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
5061
import org.springframework.test.annotation.DirtiesContext;
5162
import org.springframework.test.context.ContextConfiguration;
5263
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -195,16 +206,25 @@ public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviou
195206
runFailedJob(new JobParametersBuilder().addLong("run.id", 1L)
196207
.addLong("id", 2L, false).addLong("foo", 3L, false).toJobParameters());
197208
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
198-
JobInstance jobInstance = this.jobExplorer.getJobInstance(0L);
199-
assertThat(this.jobExplorer.getJobExecutions(jobInstance)).hasSize(2);
209+
JobInstance jobInstance = jobExplorer.getLastJobInstance("job");
210+
211+
List<JobExecution> executions = this.jobExplorer.getJobExecutions(jobInstance);
212+
213+
assertThat(executions).hasSize(2);
214+
215+
JobExecution firstJobExecution = executions.get(0);
216+
JobExecution secondJobExecution = executions.get(1);
217+
if ((executions.get(0).getId() > executions.get(1).getId())) {
218+
firstJobExecution = executions.get(1);
219+
secondJobExecution = executions.get(0);
220+
}
221+
200222
// first execution
201-
JobExecution firstJobExecution = this.jobExplorer.getJobExecution(0L);
202223
JobParameters parameters = firstJobExecution.getJobParameters();
203224
assertThat(parameters.getLong("run.id")).isEqualTo(1L);
204-
assertThat(parameters.getLong("id")).isEqualTo(1L);
205-
assertThat(parameters.getLong("foo")).isEqualTo(2L);
225+
assertThat(parameters.getLong("id")).isEqualTo(2L);
226+
assertThat(parameters.getLong("foo")).isEqualTo(3L);
206227
// second execution
207-
JobExecution secondJobExecution = this.jobExplorer.getJobExecution(1L);
208228
parameters = secondJobExecution.getJobParameters();
209229
// identifying parameters should be the same as previous execution
210230
assertThat(parameters.getLong("run.id")).isEqualTo(1L);
@@ -232,21 +252,34 @@ private void runFailedJob(JobParameters jobParameters) throws Exception {
232252

233253
@Configuration
234254
@EnableBatchProcessing
255+
@Import(EmbeddedDataSourceConfiguration.class)
256+
235257
protected static class BatchConfiguration implements BatchConfigurer {
236258

237259
private ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
238260

239261
private JobRepository jobRepository;
240262

241-
private MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(
242-
this.transactionManager);
263+
@Autowired
264+
private DataSource dataSource;
243265

244266
public BatchConfiguration() throws Exception {
245-
this.jobRepository = this.jobRepositoryFactory.getObject();
267+
}
268+
269+
private JobRepository jobRepositoryNew() throws Exception {
270+
JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
271+
jobRepositoryFactoryBean.setDataSource(dataSource);
272+
jobRepositoryFactoryBean.setTransactionManager(transactionManager);
273+
jobRepositoryFactoryBean.setSerializer(new DefaultExecutionContextSerializer());
274+
this.jobRepository = jobRepositoryFactoryBean.getObject();
275+
return this.jobRepository;
246276
}
247277

248278
@Override
249-
public JobRepository getJobRepository() {
279+
public JobRepository getJobRepository() throws Exception {
280+
if (this.jobRepository == null) {
281+
this.jobRepository = jobRepositoryNew();
282+
}
250283
return this.jobRepository;
251284
}
252285

@@ -256,18 +289,36 @@ public PlatformTransactionManager getTransactionManager() {
256289
}
257290

258291
@Override
259-
public JobLauncher getJobLauncher() {
292+
public JobLauncher getJobLauncher() throws Exception {
260293
SimpleJobLauncher launcher = new SimpleJobLauncher();
261-
launcher.setJobRepository(this.jobRepository);
294+
295+
launcher.setJobRepository(getJobRepository());
262296
launcher.setTaskExecutor(new SyncTaskExecutor());
263297
return launcher;
264298
}
265299

266300
@Override
267301
public JobExplorer getJobExplorer() throws Exception {
268-
return new MapJobExplorerFactoryBean(this.jobRepositoryFactory).getObject();
302+
dataSourceInitializer().afterPropertiesSet();
303+
JobExplorerFactoryBean factoryBean = new JobExplorerFactoryBean();
304+
factoryBean.setDataSource(dataSource);
305+
factoryBean.setJdbcOperations(new JdbcTemplate(dataSource));
306+
factoryBean.setSerializer(new DefaultExecutionContextSerializer());
307+
return factoryBean.getObject();
269308
}
270309

310+
public DataSourceInitializer dataSourceInitializer() {
311+
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
312+
dataSourceInitializer.setDataSource(dataSource);
313+
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
314+
databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-h2.sql"));
315+
dataSourceInitializer.setDatabasePopulator(databasePopulator);
316+
databasePopulator = new ResourceDatabasePopulator();
317+
databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-drop-h2.sql"));
318+
dataSourceInitializer.setDatabaseCleaner(databasePopulator);
319+
return dataSourceInitializer;
320+
}
321+
271322
}
272323

273324
}

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2022 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.
@@ -88,7 +88,7 @@ public class DeployerPartitionHandlerTests {
8888

8989
@BeforeEach
9090
public void setUp() {
91-
MockitoAnnotations.initMocks(this);
91+
MockitoAnnotations.openMocks(this);
9292
this.environment = new MockEnvironment();
9393
TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(),
9494
new Date(), "", Collections.emptyList(), null, null, null);
@@ -108,7 +108,7 @@ public void testDeprecatedConstructorValidation() {
108108
this.resource, null, "A step name is required");
109109

110110
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource,
111-
"step-name");
111+
"step-name", this.taskRepository);
112112
}
113113

114114
@Test
@@ -132,7 +132,7 @@ public void testConstructorValidation() {
132132
@Test
133133
public void testNoPartitions() throws Exception {
134134
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
135-
this.jobExplorer, this.resource, "step1");
135+
this.jobExplorer, this.resource, "step1", this.taskRepository);
136136
handler.setEnvironment(this.environment);
137137

138138
StepExecution stepExecution = new StepExecution("step1", new JobExecution(1L));

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2022 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.
@@ -69,7 +69,7 @@ public class DeployerStepExecutionHandlerTests {
6969

7070
@BeforeEach
7171
public void setUp() {
72-
MockitoAnnotations.initMocks(this);
72+
MockitoAnnotations.openMocks(this);
7373

7474
this.handler = new DeployerStepExecutionHandler(this.beanFactory,
7575
this.jobExplorer, this.jobRepository);

spring-cloud-task-core/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@
7878
<optional>true</optional>
7979
</dependency>
8080
<dependency>
81-
<groupId>javax</groupId>
82-
<artifactId>javaee-api</artifactId>
83-
<version>${java-ee-api.version}</version>
81+
<groupId>jakarta.platform</groupId>
82+
<artifactId>jakarta.jakartaee-api</artifactId>
83+
<version>${jakarta-ee-api.version}</version>
8484
<optional>true</optional>
85+
<scope>provided</scope>
8586
</dependency>
8687
<dependency>
8788
<groupId>org.springframework</groupId>
@@ -128,6 +129,6 @@
128129
<version>${jmock-version}</version>
129130
<scope>test</scope>
130131
</dependency>
131-
</dependencies>
132+
</dependencies>
132133

133134
</project>

spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2022 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.
@@ -16,9 +16,9 @@
1616

1717
package org.springframework.cloud.task.configuration;
1818

19-
import javax.persistence.EntityManager;
2019
import javax.sql.DataSource;
2120

21+
import jakarta.persistence.EntityManager;
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
2424

0 commit comments

Comments
 (0)