Skip to content

Commit 617f3d5

Browse files
committed
Merge branch '3.3.x' into 3.4.x
Closes gh-44995
2 parents fc9937d + cae3a92 commit 617f3d5

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
@@ -190,7 +190,10 @@ public T build() {
190190
&& applied.contains(DataSourceProperty.URL)) {
191191
String url = properties.get(dataSource, DataSourceProperty.URL);
192192
DatabaseDriver driver = DatabaseDriver.fromJdbcUrl(url);
193-
properties.set(dataSource, DataSourceProperty.DRIVER_CLASS_NAME, driver.getDriverClassName());
193+
String driverClassName = driver.getDriverClassName();
194+
if (driverClassName != null) {
195+
properties.set(dataSource, DataSourceProperty.DRIVER_CLASS_NAME, driver.getDriverClassName());
196+
}
194197
}
195198
return dataSource;
196199
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ void buildWhenC3P0TypeSpecifiedReturnsExpectedDataSource() {
504504
assertThat(c3p0DataSource.getDriverClass()).isEqualTo("com.example.Driver");
505505
}
506506

507+
@Test
508+
void buildWhenJdbcUrlIsFromUnknownDriverLeavesDriverClassNameUnset() {
509+
this.dataSource = DataSourceBuilder.create()
510+
.url("jdbc:example://localhost:1234/example")
511+
.type(HikariDataSource.class)
512+
.build();
513+
assertThat(((HikariDataSource) this.dataSource).getDriverClassName()).isNull();
514+
}
515+
507516
private DataSource wrap(DataSource target) {
508517
return new DataSourceWrapper(target);
509518
}

0 commit comments

Comments
 (0)