mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Revert strange looking DataSource chamge
This commit is contained in:
parent
510e16a809
commit
7e579d3652
@ -1,7 +1,7 @@
|
||||
handlers = java.util.logging.ConsoleHandler
|
||||
.level = INFO
|
||||
|
||||
java.util.logging.ConsoleHandler.level = FINE
|
||||
sun.net.www.protocol.http.HttpURLConnection.level = ALL
|
||||
org.springframework.bootstrap.level = ALL
|
||||
org.springframework.security.level = ALL
|
||||
#java.util.logging.ConsoleHandler.level = FINE
|
||||
#sun.net.www.protocol.http.HttpURLConnection.level = ALL
|
||||
#org.springframework.bootstrap.level = ALL
|
||||
#org.springframework.security.level = ALL
|
||||
|
@ -55,7 +55,7 @@ public class ManagementAddressServiceBootstrapApplicationTests {
|
||||
.run(ServiceBootstrapApplication.class, args);
|
||||
}
|
||||
});
|
||||
context = future.get(10, TimeUnit.SECONDS);
|
||||
context = future.get(30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -47,7 +47,7 @@ public class ManagementServiceBootstrapApplicationTests {
|
||||
.run(ServiceBootstrapApplication.class, args);
|
||||
}
|
||||
});
|
||||
context = future.get(10, TimeUnit.SECONDS);
|
||||
context = future.get(30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -58,7 +58,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(EmbeddedDatabaseType.class /* Spring JDBC */)
|
||||
// @ConditionalOnMissingBean(DataSource.class)
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
public class DataSourceAutoConfiguration {
|
||||
|
||||
// FIXME see above
|
||||
@ -109,7 +109,7 @@ public class DataSourceAutoConfiguration {
|
||||
}
|
||||
|
||||
// FIXME: DB platform
|
||||
@Value("${spring.database.schema:classpath*:schema.sql}")
|
||||
@Value("${spring.database.schema:classpath*:schema-${spring.database.platform:all}.sql}")
|
||||
private String schemaLocations = "";
|
||||
|
||||
@PostConstruct
|
||||
|
@ -21,9 +21,12 @@ import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.junit.Test;
|
||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@ -49,6 +52,17 @@ public class DataSourceAutoConfigurationTests {
|
||||
assertNotNull(this.context.getBean(DataSource.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultDataSourceCanBeOverridden() throws Exception {
|
||||
this.context.register(TestDataSourceConfiguration.class,
|
||||
DataSourceAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
assertTrue("DataSource is wrong type: " + dataSource,
|
||||
dataSource instanceof BasicDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcTemplateExists() throws Exception {
|
||||
this.context.register(DataSourceAutoConfiguration.class,
|
||||
@ -85,4 +99,20 @@ public class DataSourceAutoConfigurationTests {
|
||||
template.queryForObject("SELECT COUNT(*) from FOO", Integer.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestDataSourceConfiguration {
|
||||
|
||||
private BasicDataSource pool;
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
this.pool = new BasicDataSource();
|
||||
this.pool.setDriverClassName("org.hsqldb.jdbcDriver");
|
||||
this.pool.setUrl("jdbc:hsqldb:overridedb");
|
||||
this.pool.setUsername("sa");
|
||||
return this.pool;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user