mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +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
|
handlers = java.util.logging.ConsoleHandler
|
||||||
.level = INFO
|
.level = INFO
|
||||||
|
|
||||||
java.util.logging.ConsoleHandler.level = FINE
|
#java.util.logging.ConsoleHandler.level = FINE
|
||||||
sun.net.www.protocol.http.HttpURLConnection.level = ALL
|
#sun.net.www.protocol.http.HttpURLConnection.level = ALL
|
||||||
org.springframework.bootstrap.level = ALL
|
#org.springframework.bootstrap.level = ALL
|
||||||
org.springframework.security.level = ALL
|
#org.springframework.security.level = ALL
|
||||||
|
@ -55,7 +55,7 @@ public class ManagementAddressServiceBootstrapApplicationTests {
|
|||||||
.run(ServiceBootstrapApplication.class, args);
|
.run(ServiceBootstrapApplication.class, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context = future.get(10, TimeUnit.SECONDS);
|
context = future.get(30, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -47,7 +47,7 @@ public class ManagementServiceBootstrapApplicationTests {
|
|||||||
.run(ServiceBootstrapApplication.class, args);
|
.run(ServiceBootstrapApplication.class, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context = future.get(10, TimeUnit.SECONDS);
|
context = future.get(30, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -58,7 +58,7 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass(EmbeddedDatabaseType.class /* Spring JDBC */)
|
@ConditionalOnClass(EmbeddedDatabaseType.class /* Spring JDBC */)
|
||||||
// @ConditionalOnMissingBean(DataSource.class)
|
@ConditionalOnMissingBean(DataSource.class)
|
||||||
public class DataSourceAutoConfiguration {
|
public class DataSourceAutoConfiguration {
|
||||||
|
|
||||||
// FIXME see above
|
// FIXME see above
|
||||||
@ -109,7 +109,7 @@ public class DataSourceAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: DB platform
|
// FIXME: DB platform
|
||||||
@Value("${spring.database.schema:classpath*:schema.sql}")
|
@Value("${spring.database.schema:classpath*:schema-${spring.database.platform:all}.sql}")
|
||||||
private String schemaLocations = "";
|
private String schemaLocations = "";
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
|
@ -21,9 +21,12 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
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.core.env.MapPropertySource;
|
||||||
import org.springframework.jdbc.core.JdbcOperations;
|
import org.springframework.jdbc.core.JdbcOperations;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
@ -49,6 +52,17 @@ public class DataSourceAutoConfigurationTests {
|
|||||||
assertNotNull(this.context.getBean(DataSource.class));
|
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
|
@Test
|
||||||
public void testJdbcTemplateExists() throws Exception {
|
public void testJdbcTemplateExists() throws Exception {
|
||||||
this.context.register(DataSourceAutoConfiguration.class,
|
this.context.register(DataSourceAutoConfiguration.class,
|
||||||
@ -85,4 +99,20 @@ public class DataSourceAutoConfigurationTests {
|
|||||||
template.queryForObject("SELECT COUNT(*) from FOO", Integer.class));
|
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