Skip to content

Commit db6e9a7

Browse files
committed
Start building against Spring Batch 5.0 snapshots
This commit adapts to some changes in Spring Batch 5.0: - A DataSource bean is now required by Batch - A PlatformTransactionManager bean is no longer defined by Batch See gh-29278
1 parent 9bc1047 commit db6e9a7

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-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.
@@ -64,7 +64,7 @@
6464
@Configuration(proxyBeanMethods = false)
6565
@ConditionalOnClass({ JobLauncher.class, DataSource.class })
6666
@AutoConfigureAfter(HibernateJpaAutoConfiguration.class)
67-
@ConditionalOnBean(JobLauncher.class)
67+
@ConditionalOnBean({ DataSource.class, JobLauncher.class })
6868
@EnableConfigurationProperties(BatchProperties.class)
6969
@Import({ BatchConfigurerConfiguration.class, DatabaseInitializationDependencyConfigurer.class })
7070
public class BatchAutoConfiguration {
@@ -103,7 +103,6 @@ public SimpleJobOperator jobOperator(ObjectProvider<JobParametersConverter> jobP
103103
}
104104

105105
@Configuration(proxyBeanMethods = false)
106-
@ConditionalOnBean(DataSource.class)
107106
@ConditionalOnClass(DatabasePopulator.class)
108107
@Conditional(OnBatchDatasourceInitializationCondition.class)
109108
static class DataSourceInitializerConfiguration {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,6 @@ void testDefaultContext() {
101101
});
102102
}
103103

104-
@Test
105-
void whenThereIsNoDataSourceAutoConfigurationBacksOff() {
106-
this.contextRunner.withUserConfiguration(TestConfiguration.class)
107-
.run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.class));
108-
}
109-
110-
@Test
111-
void whenThereIsAnEntityManagerFactoryButNoDataSourceAutoConfigurationBacksOff() {
112-
this.contextRunner.withUserConfiguration(TestConfiguration.class, EntityManagerFactoryConfiguration.class)
113-
.run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.class));
114-
}
115-
116104
@Test
117105
void testNoBatchConfiguration() {
118106
this.contextRunner.withUserConfiguration(EmptyConfiguration.class, EmbeddedDataSourceConfiguration.class)

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJdbcTests.java

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

1717
package org.springframework.boot.autoconfigure.batch;
1818

19+
import javax.sql.DataSource;
20+
21+
import com.zaxxer.hikari.HikariDataSource;
1922
import org.junit.jupiter.api.Test;
2023

2124
import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
@@ -28,6 +31,7 @@
2831
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
2932
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3033
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
34+
import org.springframework.context.annotation.Bean;
3135
import org.springframework.context.annotation.Configuration;
3236
import org.springframework.transaction.PlatformTransactionManager;
3337

@@ -59,6 +63,11 @@ void whenThereIsNoJdbcOnTheClasspathThenComponentsAreStillAutoConfigured() {
5963
@EnableBatchProcessing
6064
static class BatchConfiguration implements BatchConfigurer {
6165

66+
@Bean
67+
DataSource dataSource() {
68+
return new HikariDataSource();
69+
}
70+
6271
@Override
6372
public JobRepository getJobRepository() {
6473
return mock(JobRepository.class);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
import org.springframework.boot.autoconfigure.AutoConfigurations;
2929
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
3030
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
31+
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener;
3132
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
3233
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
34+
import org.springframework.boot.logging.LogLevel;
3335
import org.springframework.boot.sql.init.DatabaseInitializationMode;
3436
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3537
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
3638
import org.springframework.jdbc.core.JdbcTemplate;
37-
import org.springframework.transaction.PlatformTransactionManager;
3839

3940
import static org.assertj.core.api.Assertions.assertThat;
4041

@@ -52,13 +53,11 @@ class BatchAutoConfigurationWithoutJpaTests {
5253
@Test
5354
void jdbcWithDefaultSettings() {
5455
this.contextRunner.withUserConfiguration(DefaultConfiguration.class, EmbeddedDataSourceConfiguration.class)
55-
.withPropertyValues("spring.datasource.generate-unique-name=true").run((context) -> {
56+
.withPropertyValues("spring.datasource.generate-unique-name=true")
57+
.withInitializer(new ConditionEvaluationReportLoggingListener(LogLevel.INFO)).run((context) -> {
5658
assertThat(context).hasSingleBean(JobLauncher.class);
5759
assertThat(context).hasSingleBean(JobExplorer.class);
5860
assertThat(context).hasSingleBean(JobRepository.class);
59-
assertThat(context).hasSingleBean(PlatformTransactionManager.class);
60-
assertThat(context.getBean(PlatformTransactionManager.class).toString())
61-
.contains("DataSourceTransactionManager");
6261
assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema())
6362
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
6463
assertThat(context.getBean(BasicBatchConfigurer.class).determineIsolationLevel()).isNull();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-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.
@@ -43,6 +43,7 @@
4343
import org.springframework.batch.core.step.tasklet.Tasklet;
4444
import org.springframework.boot.autoconfigure.AutoConfigurations;
4545
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
46+
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
4647
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
4748
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
4849
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
@@ -68,8 +69,8 @@
6869
class JobLauncherApplicationRunnerTests {
6970

7071
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
71-
.withConfiguration(
72-
AutoConfigurations.of(DataSourceAutoConfiguration.class, TransactionAutoConfiguration.class))
72+
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
73+
TransactionAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class))
7374
.withUserConfiguration(BatchConfiguration.class);
7475

7576
@Test

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ bom {
13201320
]
13211321
}
13221322
}
1323-
library("Spring Batch", "4.3.4") {
1323+
library("Spring Batch", "5.0.0-SNAPSHOT") {
13241324
group("org.springframework.batch") {
13251325
modules = [
13261326
"spring-batch-core",

0 commit comments

Comments
 (0)