diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConfigurerConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConfigurerConfiguration.java index 4fb53716dc..afa868a4eb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConfigurerConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConfigurerConfiguration.java @@ -40,6 +40,7 @@ import org.springframework.transaction.PlatformTransactionManager; class BatchConfigurerConfiguration { @Configuration + @ConditionalOnBean(DataSource.class) @ConditionalOnMissingBean(name = "entityManagerFactory") static class JdbcBatchConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index f0a2409970..f8ab193bd2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -89,7 +89,13 @@ public class BatchAutoConfigurationTests { } @Test - public void testNoDatabase() { + public void whenThereIsNoDataSourceAutoConfigurationBacksOff() { + this.contextRunner.withUserConfiguration(TestConfiguration.class) + .run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.class)); + } + + @Test + public void testCustomConfigurationWithNoDatabase() { this.contextRunner.withUserConfiguration(TestCustomConfiguration.class).run((context) -> { assertThat(context).hasSingleBean(JobLauncher.class); JobExplorer explorer = context.getBean(JobExplorer.class);