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
pull/29446/head
Andy Wilkinson 3 years ago
parent 9bc1047c49
commit db6e9a7a5f

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -64,7 +64,7 @@ import org.springframework.util.StringUtils;
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ JobLauncher.class, DataSource.class })
@AutoConfigureAfter(HibernateJpaAutoConfiguration.class)
@ConditionalOnBean(JobLauncher.class)
@ConditionalOnBean({ DataSource.class, JobLauncher.class })
@EnableConfigurationProperties(BatchProperties.class)
@Import({ BatchConfigurerConfiguration.class, DatabaseInitializationDependencyConfigurer.class })
public class BatchAutoConfiguration {
@ -103,7 +103,6 @@ public class BatchAutoConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(DataSource.class)
@ConditionalOnClass(DatabasePopulator.class)
@Conditional(OnBatchDatasourceInitializationCondition.class)
static class DataSourceInitializerConfiguration {

@ -101,18 +101,6 @@ class BatchAutoConfigurationTests {
});
}
@Test
void whenThereIsNoDataSourceAutoConfigurationBacksOff() {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.class));
}
@Test
void whenThereIsAnEntityManagerFactoryButNoDataSourceAutoConfigurationBacksOff() {
this.contextRunner.withUserConfiguration(TestConfiguration.class, EntityManagerFactoryConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.class));
}
@Test
void testNoBatchConfiguration() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class, EmbeddedDataSourceConfiguration.class)

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,9 @@
package org.springframework.boot.autoconfigure.batch;
import javax.sql.DataSource;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.jupiter.api.Test;
import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
@ -28,6 +31,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
@ -59,6 +63,11 @@ class BatchAutoConfigurationWithoutJdbcTests {
@EnableBatchProcessing
static class BatchConfiguration implements BatchConfigurer {
@Bean
DataSource dataSource() {
return new HikariDataSource();
}
@Override
public JobRepository getJobRepository() {
return mock(JobRepository.class);

@ -28,13 +28,14 @@ import org.springframework.batch.core.repository.JobRepository;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener;
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.sql.init.DatabaseInitializationMode;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import static org.assertj.core.api.Assertions.assertThat;
@ -52,13 +53,11 @@ class BatchAutoConfigurationWithoutJpaTests {
@Test
void jdbcWithDefaultSettings() {
this.contextRunner.withUserConfiguration(DefaultConfiguration.class, EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.datasource.generate-unique-name=true").run((context) -> {
.withPropertyValues("spring.datasource.generate-unique-name=true")
.withInitializer(new ConditionEvaluationReportLoggingListener(LogLevel.INFO)).run((context) -> {
assertThat(context).hasSingleBean(JobLauncher.class);
assertThat(context).hasSingleBean(JobExplorer.class);
assertThat(context).hasSingleBean(JobRepository.class);
assertThat(context).hasSingleBean(PlatformTransactionManager.class);
assertThat(context.getBean(PlatformTransactionManager.class).toString())
.contains("DataSourceTransactionManager");
assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema())
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(context.getBean(BasicBatchConfigurer.class).determineIsolationLevel()).isNull();

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,6 +43,7 @@ import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
@ -68,8 +69,8 @@ import static org.assertj.core.api.Assertions.fail;
class JobLauncherApplicationRunnerTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(DataSourceAutoConfiguration.class, TransactionAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
TransactionAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class))
.withUserConfiguration(BatchConfiguration.class);
@Test

@ -1320,7 +1320,7 @@ bom {
]
}
}
library("Spring Batch", "4.3.4") {
library("Spring Batch", "5.0.0-SNAPSHOT") {
group("org.springframework.batch") {
modules = [
"spring-batch-core",

Loading…
Cancel
Save