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 abe9f446aa..259b47e013 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 @@ -35,12 +35,12 @@ import org.springframework.transaction.PlatformTransactionManager; * @author Stephane Nicoll */ @ConditionalOnClass(PlatformTransactionManager.class) +@ConditionalOnBean(DataSource.class) @ConditionalOnMissingBean(BatchConfigurer.class) @Configuration(proxyBeanMethods = false) class BatchConfigurerConfiguration { @Configuration(proxyBeanMethods = false) - @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 8777636f74..d80a778744 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 @@ -63,6 +63,7 @@ import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.Mockito.mock; /** * Tests for {@link BatchAutoConfiguration}. @@ -96,6 +97,12 @@ class BatchAutoConfigurationTests { .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 testCustomConfigurationWithNoDatabase() { this.contextRunner.withUserConfiguration(TestCustomConfiguration.class).run((context) -> { @@ -283,6 +290,16 @@ class BatchAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class EntityManagerFactoryConfiguration { + + @Bean + EntityManagerFactory entityManagerFactory() { + return mock(EntityManagerFactory.class); + } + + } + @EnableBatchProcessing @TestAutoConfigurationPackage(City.class) static class TestCustomConfiguration implements BatchConfigurer {