Skip to content

Commit 740fe4b

Browse files
committed
Merge branch '3.4.x'
Closes gh-44996
2 parents 39ef5ae + 617f3d5 commit 740fe4b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ public T build() {
191191
&& applied.contains(DataSourceProperty.URL)) {
192192
String url = properties.get(dataSource, DataSourceProperty.URL);
193193
DatabaseDriver driver = DatabaseDriver.fromJdbcUrl(url);
194-
properties.set(dataSource, DataSourceProperty.DRIVER_CLASS_NAME, driver.getDriverClassName());
194+
String driverClassName = driver.getDriverClassName();
195+
if (driverClassName != null) {
196+
properties.set(dataSource, DataSourceProperty.DRIVER_CLASS_NAME, driver.getDriverClassName());
197+
}
195198
}
196199
return dataSource;
197200
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,15 @@ void buildWhenViburTypeSpecifiedReturnsExpectedDataSource() {
522522
assertThat(viburDataSource.getDriverClassName()).isEqualTo("com.example.Driver");
523523
}
524524

525+
@Test
526+
void buildWhenJdbcUrlIsFromUnknownDriverLeavesDriverClassNameUnset() {
527+
this.dataSource = DataSourceBuilder.create()
528+
.url("jdbc:example://localhost:1234/example")
529+
.type(HikariDataSource.class)
530+
.build();
531+
assertThat(((HikariDataSource) this.dataSource).getDriverClassName()).isNull();
532+
}
533+
525534
private DataSource wrap(DataSource target) {
526535
return new DataSourceWrapper(target);
527536
}

0 commit comments

Comments
 (0)