Skip to content

Commit 15375fd

Browse files
committed
Merge branch '2.4.x'
Closes gh-25342
2 parents 274a985 + 5d1bb30 commit 15375fd

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

+3-1
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.
@@ -196,6 +196,8 @@ private static class DataSourceSettingsResolver {
196196
(aliases) -> aliases.addAliases("driver-class-name", "driver-class"))));
197197
addIfAvailable(this.allDataSourceSettings,
198198
create(classLoader, "oracle.jdbc.datasource.OracleDataSource", OracleDataSourceSettings::new));
199+
addIfAvailable(this.allDataSourceSettings, create(classLoader, "org.h2.jdbcx.JdbcDataSource",
200+
(type) -> new DataSourceSettings(type, (aliases) -> aliases.addAliases("username", "user"))));
199201
}
200202

201203
private static List<DataSourceSettings> resolveAvailableDataSourceSettings(ClassLoader classLoader) {

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

+11-1
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").type(JdbcDataSource.class).username("test")
126+
.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)