Merge branch '2.1.x'

Closes gh-17466
pull/17471/head
Andy Wilkinson 5 years ago
commit edff0f87e2

@ -35,12 +35,12 @@ import org.springframework.transaction.PlatformTransactionManager;
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
@ConditionalOnClass(PlatformTransactionManager.class) @ConditionalOnClass(PlatformTransactionManager.class)
@ConditionalOnBean(DataSource.class)
@ConditionalOnMissingBean(BatchConfigurer.class) @ConditionalOnMissingBean(BatchConfigurer.class)
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class BatchConfigurerConfiguration { class BatchConfigurerConfiguration {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnBean(DataSource.class)
@ConditionalOnMissingBean(name = "entityManagerFactory") @ConditionalOnMissingBean(name = "entityManagerFactory")
static class JdbcBatchConfiguration { static class JdbcBatchConfiguration {

@ -63,6 +63,7 @@ import org.springframework.transaction.PlatformTransactionManager;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
/** /**
* Tests for {@link BatchAutoConfiguration}. * Tests for {@link BatchAutoConfiguration}.
@ -96,6 +97,12 @@ class BatchAutoConfigurationTests {
.run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.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 @Test
void testCustomConfigurationWithNoDatabase() { void testCustomConfigurationWithNoDatabase() {
this.contextRunner.withUserConfiguration(TestCustomConfiguration.class).run((context) -> { 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 @EnableBatchProcessing
@TestAutoConfigurationPackage(City.class) @TestAutoConfigurationPackage(City.class)
static class TestCustomConfiguration implements BatchConfigurer { static class TestCustomConfiguration implements BatchConfigurer {

Loading…
Cancel
Save