Make Batch auto-configuration back-off is spring-jdbc isn't present

See gh-29487
pull/31887/head
Madhura Bhave 2 years ago
parent 2804c84648
commit aac1829106

@ -41,6 +41,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.util.StringUtils;
/**
@ -60,7 +61,7 @@ import org.springframework.util.StringUtils;
* @since 1.0.0
*/
@AutoConfiguration(after = HibernateJpaAutoConfiguration.class)
@ConditionalOnClass({ JobLauncher.class, DataSource.class })
@ConditionalOnClass({ JobLauncher.class, DataSource.class, DatabasePopulator.class })
@ConditionalOnBean({ DataSource.class, JobLauncher.class })
@EnableConfigurationProperties(BatchProperties.class)
@Import({ BatchConfigurerConfiguration.class, DatabaseInitializationDependencyConfigurer.class })

@ -61,6 +61,7 @@ import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
import org.springframework.boot.sql.init.DatabaseInitializationMode;
import org.springframework.boot.sql.init.DatabaseInitializationSettings;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
@ -71,6 +72,7 @@ import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
@ -114,6 +116,15 @@ class BatchAutoConfigurationTests {
});
}
@Test
void autoconfigurationBacksOffEntirelyIfSpringJdbcAbsent() {
this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class)
.withClassLoader(new FilteredClassLoader(DatabasePopulator.class)).run((context) -> {
assertThat(context).doesNotHaveBean(JobLauncherApplicationRunner.class);
assertThat(context).doesNotHaveBean(BatchDataSourceScriptDatabaseInitializer.class);
});
}
@Test
void testDefinesAndLaunchesJob() {
this.contextRunner.withUserConfiguration(JobConfiguration.class, EmbeddedDataSourceConfiguration.class)

Loading…
Cancel
Save