mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Add support for SimpleDriverDataSource
This commit makes sure that DataSourceBuilder can configure SimpleDriverDataSource by adding an alias for the driver's class name. Closes gh-20220 Co-authored-by: Dmytro Nosan <dimanosan@gmail.com>
This commit is contained in:
parent
287d577aea
commit
4ec30e1145
@ -87,6 +87,7 @@ public final class DataSourceBuilder<T extends DataSource> {
|
|||||||
private void bind(DataSource result) {
|
private void bind(DataSource result) {
|
||||||
ConfigurationPropertySource source = new MapConfigurationPropertySource(this.properties);
|
ConfigurationPropertySource source = new MapConfigurationPropertySource(this.properties);
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
|
aliases.addAliases("driver-class-name", "driver-class");
|
||||||
aliases.addAliases("url", "jdbc-url");
|
aliases.addAliases("url", "jdbc-url");
|
||||||
aliases.addAliases("username", "user");
|
aliases.addAliases("username", "user");
|
||||||
Binder binder = new Binder(source.withAliases(aliases));
|
Binder binder = new Binder(source.withAliases(aliases));
|
||||||
|
@ -26,9 +26,12 @@ import javax.sql.DataSource;
|
|||||||
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
import org.apache.commons.dbcp2.BasicDataSource;
|
import org.apache.commons.dbcp2.BasicDataSource;
|
||||||
|
import org.h2.Driver;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,6 +77,14 @@ class DataSourceBuilderTests {
|
|||||||
assertThat(hikariDataSource).isInstanceOf(HikariDataSource.class);
|
assertThat(hikariDataSource).isInstanceOf(HikariDataSource.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void dataSourceCanBeCreatedWithSimpleDriverDataSource() {
|
||||||
|
this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test").type(SimpleDriverDataSource.class).build();
|
||||||
|
assertThat(this.dataSource).isInstanceOf(SimpleDriverDataSource.class);
|
||||||
|
assertThat(((SimpleDriverDataSource) this.dataSource).getUrl()).isEqualTo("jdbc:h2:test");
|
||||||
|
assertThat(((SimpleDriverDataSource) this.dataSource).getDriver()).isInstanceOf(Driver.class);
|
||||||
|
}
|
||||||
|
|
||||||
final class HidePackagesClassLoader extends URLClassLoader {
|
final class HidePackagesClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
private final String[] hiddenPackages;
|
private final String[] hiddenPackages;
|
||||||
|
Loading…
Reference in New Issue
Block a user