Merge branch '1.3.x'

pull/5289/head
Andy Wilkinson 9 years ago
commit cd6cacfb4f

@ -25,10 +25,13 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration.DevToolsDataSourceCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
@ -40,7 +43,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
* @since 1.3.3
*/
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
@ConditionalOnBean({ DataSource.class, DataSourceProperties.class })
@Conditional(DevToolsDataSourceCondition.class)
@Configuration
public class DevToolsDataSourceAutoConfiguration {
@ -85,4 +88,22 @@ public class DevToolsDataSourceAutoConfiguration {
}
static class DevToolsDataSourceCondition extends AllNestedConditions {
DevToolsDataSourceCondition() {
super(ConfigurationPhase.REGISTER_BEAN);
}
@ConditionalOnBean(DataSource.class)
static final class DataSourceBean {
}
@ConditionalOnBean(DataSourceProperties.class)
static final class DataSourcePropertiesBean {
}
}
}

@ -33,6 +33,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -76,6 +77,14 @@ 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))
.isEmpty();
}
private ConfigurableApplicationContext createContext(String driver,
Class<?>... classes) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@ -108,4 +117,14 @@ public class DevToolsDataSourceAutoConfigurationTests {
}
@Configuration
static class NoDataSourcePropertiesConfiguration {
@Bean
public DataSource in() {
return mock(DataSource.class);
}
}
}

Loading…
Cancel
Save