Skip to content

Commit 08513bb

Browse files
committed
1 parent 44d765b commit 08513bb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -216,6 +216,8 @@ private static List<DataSourceSettings> resolveAvailableDataSourceSettings(Class
216216
}
217217
return null;
218218
}));
219+
addIfAvailable(providers, create(classLoader, "org.h2.jdbcx.JdbcDataSource",
220+
(type) -> new DataSourceSettings(type, (aliases) -> aliases.addAliases("username", "user"))));
219221
return providers;
220222
}
221223

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceBuilderTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
3030
import oracle.ucp.jdbc.PoolDataSourceImpl;
3131
import org.apache.commons.dbcp2.BasicDataSource;
3232
import org.h2.Driver;
33+
import org.h2.jdbcx.JdbcDataSource;
3334
import org.junit.jupiter.api.AfterEach;
3435
import org.junit.jupiter.api.Test;
3536

@@ -119,6 +120,15 @@ void dataSourceCanBeCreatedWithOracleUcpDataSource() {
119120
assertThat(upcDataSource.getUser()).isEqualTo("test");
120121
}
121122

123+
@Test
124+
void dataSourceCanBeCreatedWithH2JdbcDataSource() {
125+
this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test")
126+
.type(JdbcDataSource.class).username("test").build();
127+
assertThat(this.dataSource).isInstanceOf(JdbcDataSource.class);
128+
JdbcDataSource h2DataSource = (JdbcDataSource) this.dataSource;
129+
assertThat(h2DataSource.getUser()).isEqualTo("test");
130+
}
131+
122132
@Test
123133
void dataSourceAliasesAreOnlyAppliedToRelevantDataSource() {
124134
this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test").type(TestDataSource.class).username("test")

0 commit comments

Comments
 (0)