mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Ensure JdbcTemplate and DB initializer still work when user supplies DataSource
This commit is contained in:
parent
f43cf1db61
commit
43f8a71af4
@ -64,7 +64,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(EmbeddedDatabaseType.class /* Spring JDBC */)
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
public class DataSourceAutoConfiguration implements EnvironmentAware {
|
||||
|
||||
private static Log logger = LogFactory.getLog(DataSourceAutoConfiguration.class);
|
||||
@ -138,16 +137,19 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
|
||||
}
|
||||
|
||||
@Conditional(DataSourceAutoConfiguration.EmbeddedDatabaseCondition.class)
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
@Import(EmbeddedDataSourceConfiguration.class)
|
||||
protected static class EmbeddedConfiguration {
|
||||
}
|
||||
|
||||
@Conditional(DataSourceAutoConfiguration.TomcatDatabaseCondition.class)
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
@Import(TomcatDataSourceConfiguration.class)
|
||||
protected static class TomcatConfiguration {
|
||||
}
|
||||
|
||||
@Conditional(DataSourceAutoConfiguration.BasicDatabaseCondition.class)
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
@Import(CommonsDataSourceConfiguration.class)
|
||||
protected static class DbcpConfiguration {
|
||||
}
|
||||
|
@ -75,6 +75,17 @@ public class DataSourceAutoConfigurationTests {
|
||||
assertNotNull(jdbcTemplate.getDataSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcTemplateExistsWithCustomDataSource() throws Exception {
|
||||
this.context.register(TestDataSourceConfiguration.class,
|
||||
DataSourceAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class);
|
||||
assertNotNull(jdbcTemplate);
|
||||
assertTrue(jdbcTemplate.getDataSource() instanceof BasicDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedParameterJdbcTemplateExists() throws Exception {
|
||||
this.context.register(DataSourceAutoConfiguration.class,
|
||||
|
Loading…
Reference in New Issue
Block a user