Make DevTools DataSource auto-config back off without DataSourceProperties

Previously, if DataSourceAutoConfiguration had been explicitly excluded,
DevToolsDataSourceAutoConfiguration would cause refresh to fail due to
a missing DataSourceProperties bean. This commit corrects the condition
so that the auto-configuration is conditional on a DataSource bean and
a DataSourceProperties bean rather than only being conditional on one or
the other.

Closes gh-5269
This commit is contained in:
Andy Wilkinson
2016-02-29 11:37:17 +00:00
parent 5680ffdedb
commit 7a4e061de5
2 changed files with 43 additions and 1 deletions

View File

@@ -33,6 +33,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -76,6 +78,15 @@ public class DevToolsDataSourceAutoConfigurationTests {
verify(statement).execute("SHUTDOWN");
}
@Test
public void configurationBacksOffWithoutDataSourceProperties() throws SQLException {
ConfigurableApplicationContext context = createContext("org.h2.Driver",
NoDataSourcePropertiesConfiguration.class);
assertThat(
context.getBeansOfType(DevToolsDataSourceAutoConfiguration.class).size(),
is(0));
}
private ConfigurableApplicationContext createContext(String driver,
Class<?>... classes) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@@ -108,4 +119,14 @@ public class DevToolsDataSourceAutoConfigurationTests {
}
@Configuration
static class NoDataSourcePropertiesConfiguration {
@Bean
public DataSource in() {
return mock(DataSource.class);
}
}
}